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-2024 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 ($_POST['action']) {
|
42
|
if ($_POST['action'] == "kill") {
|
43
|
$port = $_POST['port'];
|
44
|
$remipp = $_POST['remipp'];
|
45
|
$client_id = $_POST['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
|
{
|
88
|
type: "post",
|
89
|
data: {
|
90
|
action: "kill",
|
91
|
port: mport,
|
92
|
remipp: remipp,
|
93
|
client_id: client_id
|
94
|
},
|
95
|
complete: killComplete
|
96
|
}
|
97
|
);
|
98
|
}
|
99
|
|
100
|
function killComplete(req) {
|
101
|
var values = req.responseText.split("|");
|
102
|
if (values[3] != "0") {
|
103
|
// alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
|
104
|
return;
|
105
|
}
|
106
|
|
107
|
$('tr[id="r:' + values[1] + ":" + values[2] + '"]').each(
|
108
|
function(index,row) { $(row).fadeOut(1000); }
|
109
|
);
|
110
|
}
|
111
|
|
112
|
function showRuleContents(vpnid, username, port) {
|
113
|
$('#rulesviewer_text').text("...Loading...");
|
114
|
$('#rulesviewer').modal('show');
|
115
|
|
116
|
$.ajax(
|
117
|
"<?=$_SERVER['SCRIPT_NAME'];?>",
|
118
|
{
|
119
|
type: 'post',
|
120
|
data: {
|
121
|
vpnid: vpnid,
|
122
|
username: username,
|
123
|
port: port,
|
124
|
action: 'showrule'
|
125
|
},
|
126
|
complete: ruleComplete
|
127
|
}
|
128
|
);
|
129
|
}
|
130
|
|
131
|
function ruleComplete(req) {
|
132
|
$('#rulesviewer_text').text(atob(req.responseText));
|
133
|
$('#rulesviewer_text').attr('readonly', true);
|
134
|
}
|
135
|
|
136
|
//]]>
|
137
|
</script>
|
138
|
|
139
|
<?php
|
140
|
$i = 0;
|
141
|
foreach ($servers as $server):
|
142
|
?>
|
143
|
|
144
|
<div class="panel panel-default">
|
145
|
<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>
|
146
|
<div class="panel-body table-responsive">
|
147
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
|
148
|
<thead>
|
149
|
<tr>
|
150
|
<th><?=gettext("Common Name")?></th>
|
151
|
<th><?=gettext("Real Address")?></th>
|
152
|
<th><?=gettext("Virtual Address"); ?></th>
|
153
|
<th><?=gettext("Last Change"); ?></th>
|
154
|
<th><?=gettext("Bytes Sent")?></th>
|
155
|
<th><?=gettext("Bytes Received")?></th>
|
156
|
<th><?=gettext("Cipher")?></th>
|
157
|
<th><?=gettext("Actions")?></th>
|
158
|
</tr>
|
159
|
</thead>
|
160
|
<tbody>
|
161
|
|
162
|
<?php
|
163
|
foreach ($server['conns'] as $conn):
|
164
|
$remote_port = substr($conn['remote_host'], strpos($conn['remote_host'], ':') + 1);
|
165
|
$rulesfile = "{$g['tmp_path']}/ovpn_ovpns{$server['vpnid']}_{$conn['user_name']}_{$remote_port}.rules";
|
166
|
?>
|
167
|
<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
|
168
|
<td>
|
169
|
<?=$conn['common_name'];?>
|
170
|
<?php if (!empty($conn['common_name']) && !empty($conn['user_name']) && ($conn['user_name'] != "UNDEF")): ?>
|
171
|
<br />
|
172
|
<?php endif; ?>
|
173
|
<?php if (!empty($conn['user_name']) && ($conn['user_name'] != "UNDEF")): ?>
|
174
|
<?=$conn['user_name'];?>
|
175
|
<?php endif; ?>
|
176
|
</td>
|
177
|
<td><?=$conn['remote_host'];?></td>
|
178
|
<td>
|
179
|
<?=$conn['virtual_addr'];?>
|
180
|
<?php if (!empty($conn['virtual_addr']) && !empty($conn['virtual_addr6'])): ?>
|
181
|
<br />
|
182
|
<?php endif; ?>
|
183
|
<?=$conn['virtual_addr6'];?>
|
184
|
</td>
|
185
|
<td><?=$conn['connect_time'];?></td>
|
186
|
<td data-value="<?=trim($conn['bytes_sent'])?>"><?=format_bytes($conn['bytes_sent']);?></td>
|
187
|
<td data-value="<?=trim($conn['bytes_recv'])?>"><?=format_bytes($conn['bytes_recv']);?></td>
|
188
|
<td data-value="<?=trim($conn['cipher'])?>"><?=$conn['cipher'];?></td>
|
189
|
<td>
|
190
|
|
191
|
<?php if (file_exists($rulesfile)): ?>
|
192
|
<a
|
193
|
onclick="showRuleContents('<?=$server['vpnid'];?>', '<?=$conn['user_name'];?>', '<?=$remote_port;?>');" style="cursor:pointer;"
|
194
|
title="<?php echo gettext("Show RADIUS ACL generated ruleset"); ?>">
|
195
|
<i class="fa-solid fa-info"></i>
|
196
|
</a>
|
197
|
<?php endif; ?>
|
198
|
<a
|
199
|
onclick="killClient('<?=$server['mgmt'];?>', '<?=$conn['remote_host'];?>', '');" style="cursor:pointer;"
|
200
|
id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
|
201
|
title="<?php echo sprintf(gettext("Kill client connection from %s"), $conn['remote_host']); ?>">
|
202
|
<i class="fa-solid fa-times"></i>
|
203
|
</a>
|
204
|
<a
|
205
|
onclick="killClient('<?=$server['mgmt'];?>', '<?=$conn['remote_host'];?>', '<?=$conn['client_id'];?>');" style="cursor:pointer;"
|
206
|
id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
|
207
|
title="<?php echo sprintf(gettext("Halt client connection from %s"), $conn['remote_host']); ?>">
|
208
|
<i class="fa-solid fa-times-circle text-danger"></i>
|
209
|
</a>
|
210
|
</td>
|
211
|
</tr>
|
212
|
<?php
|
213
|
endforeach;
|
214
|
?>
|
215
|
</tbody>
|
216
|
<tfoot>
|
217
|
<tr>
|
218
|
<td colspan="7">
|
219
|
</td>
|
220
|
<td colspan="1">
|
221
|
<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
|
222
|
<?= get_service_status_icon($ssvc, false, true, false, "service_state"); ?>
|
223
|
<?= get_service_control_links($ssvc); ?>
|
224
|
</td>
|
225
|
</tr>
|
226
|
</tfoot>
|
227
|
</table>
|
228
|
</div>
|
229
|
</div>
|
230
|
<?php
|
231
|
if (is_array($server['routes']) && count($server['routes'])):
|
232
|
?>
|
233
|
<div id="shroutebut-<?= $i ?>">
|
234
|
<button type="button" class="btn btn-info" onClick="show_routes('tabroute-<?= $i ?>','shroutebut-<?= $i ?>')" value="<?php echo gettext("Show Routing Table"); ?>">
|
235
|
<i class="fa-solid fa-plus-circle icon-embed-btn"></i>
|
236
|
<?php echo gettext("Show Routing Table"); ?>
|
237
|
</button>
|
238
|
- <?= gettext("Display OpenVPN's internal routing table for this server.") ?>
|
239
|
<br /><br />
|
240
|
</div>
|
241
|
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
|
242
|
<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
|
243
|
<div class="panel-body table-responsive">
|
244
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
|
245
|
<thead>
|
246
|
<tr>
|
247
|
<th><?=gettext("Common Name"); ?></th>
|
248
|
<th><?=gettext("Real Address"); ?></th>
|
249
|
<th><?=gettext("Target Network"); ?></th>
|
250
|
<th><?=gettext("Last Used"); ?></th>
|
251
|
</tr>
|
252
|
</thead>
|
253
|
<tbody>
|
254
|
|
255
|
<?php
|
256
|
foreach ($server['routes'] as $conn):
|
257
|
?>
|
258
|
<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
|
259
|
<td><?=$conn['common_name'];?></td>
|
260
|
<td><?=$conn['remote_host'];?></td>
|
261
|
<td><?=$conn['virtual_addr'];?></td>
|
262
|
<td><?=$conn['last_time'];?></td>
|
263
|
</tr>
|
264
|
<?php
|
265
|
endforeach;
|
266
|
?>
|
267
|
</tbody>
|
268
|
<tfoot>
|
269
|
<tr>
|
270
|
<td colspan="4"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
|
271
|
</tr>
|
272
|
</tfoot>
|
273
|
</table>
|
274
|
</div>
|
275
|
</div>
|
276
|
<?php
|
277
|
endif;
|
278
|
?>
|
279
|
<br />
|
280
|
<?php
|
281
|
$i++;
|
282
|
endforeach;
|
283
|
?>
|
284
|
<br />
|
285
|
|
286
|
<?php
|
287
|
if (!empty($sk_servers)) {
|
288
|
?>
|
289
|
<div class="panel panel-default">
|
290
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("Peer to Peer Server Instance Statistics"); ?></h2></div>
|
291
|
<div class="panel-body table-responsive">
|
292
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
|
293
|
<thead>
|
294
|
<tr>
|
295
|
<th><?=gettext("Name"); ?></th>
|
296
|
<th><?=gettext("Status"); ?></th>
|
297
|
<th><?=gettext("Last Change"); ?></th>
|
298
|
<th><?=gettext("Virtual Address"); ?></th>
|
299
|
<th><?=gettext("Remote Host"); ?></th>
|
300
|
<th><?=gettext("Bytes Sent"); ?></th>
|
301
|
<th><?=gettext("Bytes Received"); ?></th>
|
302
|
<th><?=gettext("Service"); ?></th>
|
303
|
</tr>
|
304
|
</thead>
|
305
|
<tbody>
|
306
|
|
307
|
<?php
|
308
|
foreach ($sk_servers as $sk_server):
|
309
|
?>
|
310
|
<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
|
311
|
<td>
|
312
|
ovpns<?=$sk_server['vpnid'];?><br/>
|
313
|
<?=htmlspecialchars($sk_server['name']);?>
|
314
|
</td>
|
315
|
<td><?=$sk_server['status'];?></td>
|
316
|
<td><?=$sk_server['connect_time'];?></td>
|
317
|
<td>
|
318
|
<?=$sk_server['virtual_addr'];?>
|
319
|
<?php if (!empty($sk_server['virtual_addr']) && !empty($sk_server['virtual_addr6'])): ?>
|
320
|
<br />
|
321
|
<?php endif; ?>
|
322
|
<?=$sk_server['virtual_addr6'];?>
|
323
|
</td>
|
324
|
<td><?=$sk_server['remote_host'];?></td>
|
325
|
<td data-value="<?=trim($sk_server['bytes_sent'])?>"><?=format_bytes($sk_server['bytes_sent']);?></td>
|
326
|
<td data-value="<?=trim($sk_server['bytes_recv'])?>"><?=format_bytes($sk_server['bytes_recv']);?></td>
|
327
|
<td>
|
328
|
<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
|
329
|
<?= get_service_status_icon($ssvc, false, true); ?>
|
330
|
<?= get_service_control_links($ssvc, true); ?>
|
331
|
</td>
|
332
|
</tr>
|
333
|
<?php
|
334
|
endforeach;
|
335
|
?>
|
336
|
</tbody>
|
337
|
</table>
|
338
|
</div>
|
339
|
</div>
|
340
|
|
341
|
<?php
|
342
|
}
|
343
|
?>
|
344
|
<br />
|
345
|
<?php
|
346
|
if (!empty($clients)) {
|
347
|
?>
|
348
|
<div class="panel panel-default">
|
349
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("Client Instance Statistics"); ?></h2></div>
|
350
|
<div class="panel-body table-responsive">
|
351
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
|
352
|
<thead>
|
353
|
<tr>
|
354
|
<th><?=gettext("Name"); ?></th>
|
355
|
<th><?=gettext("Status"); ?></th>
|
356
|
<th><?=gettext("Last Change"); ?></th>
|
357
|
<th><?=gettext("Local Address"); ?></th>
|
358
|
<th><?=gettext("Virtual Address"); ?></th>
|
359
|
<th><?=gettext("Remote Host"); ?></th>
|
360
|
<th><?=gettext("Bytes Sent"); ?></th>
|
361
|
<th><?=gettext("Bytes Received"); ?></th>
|
362
|
<th><?=gettext("Service"); ?></th>
|
363
|
</tr>
|
364
|
</thead>
|
365
|
<tbody>
|
366
|
|
367
|
<?php
|
368
|
foreach ($clients as $client):
|
369
|
?>
|
370
|
<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
|
371
|
<td>
|
372
|
ovpnc<?= $client['vpnid'] ?><br/>
|
373
|
<?=htmlspecialchars($client['name']);?>
|
374
|
</td>
|
375
|
<td><?=$client['status'];?></td>
|
376
|
<td><?=$client['connect_time'];?></td>
|
377
|
<td>
|
378
|
<?php if (empty($client['local_host']) && empty($client['local_port'])): ?>
|
379
|
(pending)
|
380
|
<?php else: ?>
|
381
|
<?=$client['local_host'];?>:<?=$client['local_port'];?>
|
382
|
<?php endif; ?>
|
383
|
</td>
|
384
|
<td>
|
385
|
<?=$client['virtual_addr'];?>
|
386
|
<?php if (!empty($client['virtual_addr']) && !empty($client['virtual_addr6'])): ?>
|
387
|
<br />
|
388
|
<?php endif; ?>
|
389
|
<?=$client['virtual_addr6'];?>
|
390
|
</td>
|
391
|
<td>
|
392
|
<?php if (empty($client['remote_host']) && empty($client['remote_port'])): ?>
|
393
|
(pending)
|
394
|
<?php else: ?>
|
395
|
<?=$client['remote_host'];?>:<?=$client['remote_port'];?>
|
396
|
<?php endif; ?>
|
397
|
</td>
|
398
|
<td data-value="<?=trim($client['bytes_sent'])?>"><?=format_bytes($client['bytes_sent']);?></td>
|
399
|
<td data-value="<?=trim($client['bytes_recv'])?>"><?=format_bytes($client['bytes_recv']);?></td>
|
400
|
<td>
|
401
|
<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
|
402
|
<?= get_service_status_icon($ssvc, false, true); ?>
|
403
|
<?= get_service_control_links($ssvc, true); ?>
|
404
|
</td>
|
405
|
</tr>
|
406
|
<?php
|
407
|
endforeach;
|
408
|
?>
|
409
|
</tbody>
|
410
|
</table>
|
411
|
</div>
|
412
|
</div>
|
413
|
|
414
|
<?php
|
415
|
}
|
416
|
|
417
|
if ($DisplayNote) {
|
418
|
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."));
|
419
|
}
|
420
|
|
421
|
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
|
422
|
print_info_box(gettext("No OpenVPN instances defined."));
|
423
|
}
|
424
|
|
425
|
// Create a Modal object to display RADIUS ACL generated ruleset
|
426
|
$form = new Form(FALSE);
|
427
|
$modal = new Modal('RADIUS ACL Generated Ruleset', 'rulesviewer', 'large', 'Close');
|
428
|
$modal->addInput(new Form_Textarea (
|
429
|
'rulesviewer_text',
|
430
|
null,
|
431
|
'...Loading...'
|
432
|
))->removeClass('form-control')->addClass('row-fluid col-sm-11')->setAttribute('rows', '10')->setAttribute('wrap', 'soft');
|
433
|
$form->add($modal);
|
434
|
print($form);
|
435
|
?>
|
436
|
</form>
|
437
|
|
438
|
<script type="text/javascript">
|
439
|
//<![CDATA[
|
440
|
|
441
|
function show_routes(id, buttonid) {
|
442
|
document.getElementById(buttonid).innerHTML='';
|
443
|
aodiv = document.getElementById(id);
|
444
|
aodiv.style.display = "block";
|
445
|
}
|
446
|
|
447
|
//]]>
|
448
|
</script>
|
449
|
|
450
|
<?php include("foot.inc"); ?>
|