1
|
<?php
|
2
|
/*
|
3
|
* status_openvpn.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
|
7
|
* Copyright (c) 2008 Shrew Soft Inc.
|
8
|
* All rights reserved.
|
9
|
*
|
10
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
* you may not use this file except in compliance with the License.
|
12
|
* You may obtain a copy of the License at
|
13
|
*
|
14
|
* http://www.apache.org/licenses/LICENSE-2.0
|
15
|
*
|
16
|
* Unless required by applicable law or agreed to in writing, software
|
17
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
* See the License for the specific language governing permissions and
|
20
|
* limitations under the License.
|
21
|
*/
|
22
|
|
23
|
##|+PRIV
|
24
|
##|*IDENT=page-status-openvpn
|
25
|
##|*NAME=Status: OpenVPN
|
26
|
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
|
27
|
##|*MATCH=status_openvpn.php*
|
28
|
##|-PRIV
|
29
|
|
30
|
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
|
31
|
$shortcut_section = "openvpn";
|
32
|
|
33
|
require_once("guiconfig.inc");
|
34
|
require_once("openvpn.inc");
|
35
|
require_once("shortcuts.inc");
|
36
|
require_once("service-utils.inc");
|
37
|
|
38
|
/* Handle AJAX */
|
39
|
if ($_REQUEST['action']) {
|
40
|
if ($_REQUEST['action'] == "kill") {
|
41
|
$port = $_REQUEST['port'];
|
42
|
$remipp = $_REQUEST['remipp'];
|
43
|
if (!empty($port) and !empty($remipp)) {
|
44
|
$retval = openvpn_kill_client($port, $remipp);
|
45
|
echo htmlentities("|{$port}|{$remipp}|{$retval}|");
|
46
|
} else {
|
47
|
echo gettext("invalid input");
|
48
|
}
|
49
|
exit;
|
50
|
}
|
51
|
}
|
52
|
|
53
|
$servers = openvpn_get_active_servers();
|
54
|
$sk_servers = openvpn_get_active_servers("p2p");
|
55
|
$clients = openvpn_get_active_clients();
|
56
|
|
57
|
include("head.inc"); ?>
|
58
|
|
59
|
<form action="status_openvpn.php" method="get" name="iform">
|
60
|
<script type="text/javascript">
|
61
|
//<![CDATA[
|
62
|
function killClient(mport, remipp) {
|
63
|
var busy = function(index,icon) {
|
64
|
$(icon).bind("onclick","");
|
65
|
$(icon).attr('src',$(icon).attr('src').replace("\.gif", "_d.gif"));
|
66
|
$(icon).css("cursor","wait");
|
67
|
}
|
68
|
|
69
|
$('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
|
70
|
|
71
|
$.ajax(
|
72
|
"<?=$_SERVER['SCRIPT_NAME'];?>" +
|
73
|
"?action=kill&port=" + mport + "&remipp=" + remipp,
|
74
|
{ type: "get", complete: killComplete }
|
75
|
);
|
76
|
}
|
77
|
|
78
|
function killComplete(req) {
|
79
|
var values = req.responseText.split("|");
|
80
|
if (values[3] != "0") {
|
81
|
// alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
|
82
|
return;
|
83
|
}
|
84
|
|
85
|
$('tr[id="r:' + values[1] + ":" + values[2] + '"]').each(
|
86
|
function(index,row) { $(row).fadeOut(1000); }
|
87
|
);
|
88
|
}
|
89
|
//]]>
|
90
|
</script>
|
91
|
|
92
|
<?php
|
93
|
$i = 0;
|
94
|
foreach ($servers as $server):
|
95
|
?>
|
96
|
|
97
|
<div class="panel panel-default">
|
98
|
<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext('Client Connections')?></h2></div>
|
99
|
<div class="panel-body table-responsive">
|
100
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
|
101
|
<thead>
|
102
|
<tr>
|
103
|
<th><?=gettext("Common Name")?></th>
|
104
|
<th><?=gettext("Real Address")?></th>
|
105
|
<th><?=gettext("Virtual Address"); ?></th>
|
106
|
<th><?=gettext("Connected Since"); ?></th>
|
107
|
<th><?=gettext("Bytes Sent/Received")?></th>
|
108
|
<th><!-- Icons --></th>
|
109
|
</tr>
|
110
|
</thead>
|
111
|
<tbody>
|
112
|
|
113
|
<?php
|
114
|
foreach ($server['conns'] as $conn):
|
115
|
?>
|
116
|
<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
|
117
|
<td>
|
118
|
<?=$conn['common_name'];?>
|
119
|
<?php if (!empty($conn['common_name']) && !empty($conn['user_name']) && ($conn['user_name'] != "UNDEF")): ?>
|
120
|
<br />
|
121
|
<?php endif; ?>
|
122
|
<?php if (!empty($conn['user_name']) && ($conn['user_name'] != "UNDEF")): ?>
|
123
|
<?=$conn['user_name'];?>
|
124
|
<?php endif; ?>
|
125
|
</td>
|
126
|
<td><?=$conn['remote_host'];?></td>
|
127
|
<td>
|
128
|
<?=$conn['virtual_addr'];?>
|
129
|
<?php if (!empty($conn['virtual_addr']) && !empty($conn['virtual_addr6'])): ?>
|
130
|
<br />
|
131
|
<?php endif; ?>
|
132
|
<?=$conn['virtual_addr6'];?>
|
133
|
</td>
|
134
|
<td><?=$conn['connect_time'];?></td>
|
135
|
<td><?=format_bytes($conn['bytes_sent']);?> / <?=format_bytes($conn['bytes_recv']);?></td>
|
136
|
<td>
|
137
|
<a
|
138
|
onclick="killClient('<?=$server['mgmt'];?>', '<?=$conn['remote_host'];?>');" style="cursor:pointer;"
|
139
|
id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
|
140
|
title="<?php echo sprintf(gettext("Kill client connection from %s"), $conn['remote_host']); ?>">
|
141
|
<i class="fa fa-times"></i>
|
142
|
</a>
|
143
|
</td>
|
144
|
</tr>
|
145
|
<?php
|
146
|
endforeach;
|
147
|
?>
|
148
|
</tbody>
|
149
|
<tfoot>
|
150
|
<tr>
|
151
|
<td colspan="2">
|
152
|
<table>
|
153
|
<tr>
|
154
|
<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
|
155
|
<td>
|
156
|
<?= gettext("Status") . ": " . get_service_status_icon($ssvc, false, true, false, "service_state"); ?>
|
157
|
</td>
|
158
|
<td>
|
159
|
<?= gettext("Actions") . ": " . get_service_control_links($ssvc); ?>
|
160
|
</td>
|
161
|
</tr>
|
162
|
</table>
|
163
|
</td>
|
164
|
<td colspan="5">
|
165
|
</td>
|
166
|
</tr>
|
167
|
</tfoot>
|
168
|
</table>
|
169
|
</div>
|
170
|
</div>
|
171
|
<?php
|
172
|
if (is_array($server['routes']) && count($server['routes'])):
|
173
|
?>
|
174
|
<div id="shroutebut-<?= $i ?>">
|
175
|
<button type="button" class="btn btn-info" onClick="show_routes('tabroute-<?= $i ?>','shroutebut-<?= $i ?>')" value="<?php echo gettext("Show Routing Table"); ?>">
|
176
|
<i class="fa fa-plus-circle icon-embed-btn"></i>
|
177
|
<?php echo gettext("Show Routing Table"); ?>
|
178
|
</button>
|
179
|
- <?= gettext("Display OpenVPN's internal routing table for this server.") ?>
|
180
|
<br /><br />
|
181
|
</div>
|
182
|
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
|
183
|
<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
|
184
|
<div class="panel-body table-responsive">
|
185
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
|
186
|
<thead>
|
187
|
<tr>
|
188
|
<th><?=gettext("Common Name"); ?></th>
|
189
|
<th><?=gettext("Real Address"); ?></th>
|
190
|
<th><?=gettext("Target Network"); ?></th>
|
191
|
<th><?=gettext("Last Used"); ?></th>
|
192
|
</tr>
|
193
|
</thead>
|
194
|
<tbody>
|
195
|
|
196
|
<?php
|
197
|
foreach ($server['routes'] as $conn):
|
198
|
?>
|
199
|
<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
|
200
|
<td><?=$conn['common_name'];?></td>
|
201
|
<td><?=$conn['remote_host'];?></td>
|
202
|
<td><?=$conn['virtual_addr'];?></td>
|
203
|
<td><?=$conn['last_time'];?></td>
|
204
|
</tr>
|
205
|
<?php
|
206
|
endforeach;
|
207
|
?>
|
208
|
</tbody>
|
209
|
<tfoot>
|
210
|
<tr>
|
211
|
<td colspan="4"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
|
212
|
</tr>
|
213
|
</tfoot>
|
214
|
</table>
|
215
|
</div>
|
216
|
</div>
|
217
|
<?php
|
218
|
endif;
|
219
|
?>
|
220
|
<br />
|
221
|
<?php
|
222
|
$i++;
|
223
|
endforeach;
|
224
|
?>
|
225
|
<br />
|
226
|
|
227
|
<?php
|
228
|
if (!empty($sk_servers)) {
|
229
|
?>
|
230
|
<div class="panel panel-default">
|
231
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("Peer to Peer Server Instance Statistics"); ?></h2></div>
|
232
|
<div class="panel-body table-responsive">
|
233
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
|
234
|
<thead>
|
235
|
<tr>
|
236
|
<th><?=gettext("Name"); ?></th>
|
237
|
<th><?=gettext("Status"); ?></th>
|
238
|
<th><?=gettext("Connected Since"); ?></th>
|
239
|
<th><?=gettext("Virtual Address"); ?></th>
|
240
|
<th><?=gettext("Remote Host"); ?></th>
|
241
|
<th><?=gettext("Bytes Sent / Received"); ?></th>
|
242
|
<th><?=gettext("Service"); ?></th>
|
243
|
</tr>
|
244
|
</thead>
|
245
|
<tbody>
|
246
|
|
247
|
<?php
|
248
|
foreach ($sk_servers as $sk_server):
|
249
|
?>
|
250
|
<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
|
251
|
<td><?=htmlspecialchars($sk_server['name']);?></td>
|
252
|
<td><?=$sk_server['status'];?></td>
|
253
|
<td><?=$sk_server['connect_time'];?></td>
|
254
|
<td>
|
255
|
<?=$sk_server['virtual_addr'];?>
|
256
|
<?php if (!empty($sk_server['virtual_addr']) && !empty($sk_server['virtual_addr6'])): ?>
|
257
|
<br />
|
258
|
<?php endif; ?>
|
259
|
<?=$sk_server['virtual_addr6'];?>
|
260
|
</td>
|
261
|
<td><?=$sk_server['remote_host'];?></td>
|
262
|
<td><?=format_bytes($sk_server['bytes_sent']);?> / <?=format_bytes($sk_server['bytes_recv']);?></td>
|
263
|
<td>
|
264
|
<table>
|
265
|
<tr>
|
266
|
<td>
|
267
|
<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
|
268
|
<?= get_service_status_icon($ssvc, false, true); ?>
|
269
|
<?= get_service_control_links($ssvc, true); ?>
|
270
|
</td>
|
271
|
</tr>
|
272
|
</table>
|
273
|
</td>
|
274
|
</tr>
|
275
|
<?php
|
276
|
endforeach;
|
277
|
?>
|
278
|
</tbody>
|
279
|
</table>
|
280
|
</div>
|
281
|
</div>
|
282
|
|
283
|
<?php
|
284
|
}
|
285
|
?>
|
286
|
<br />
|
287
|
<?php
|
288
|
if (!empty($clients)) {
|
289
|
?>
|
290
|
<div class="panel panel-default">
|
291
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("Client Instance Statistics"); ?></h2></div>
|
292
|
<div class="panel-body table-responsive">
|
293
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
|
294
|
<thead>
|
295
|
<tr>
|
296
|
<th><?=gettext("Name"); ?></th>
|
297
|
<th><?=gettext("Status"); ?></th>
|
298
|
<th><?=gettext("Connected Since"); ?></th>
|
299
|
<th><?=gettext("Local Address"); ?></th>
|
300
|
<th><?=gettext("Virtual Address"); ?></th>
|
301
|
<th><?=gettext("Remote Host"); ?></th>
|
302
|
<th><?=gettext("Bytes Sent/Received"); ?></th>
|
303
|
<th><?=gettext("Service"); ?></th>
|
304
|
</tr>
|
305
|
</thead>
|
306
|
<tbody>
|
307
|
|
308
|
<?php
|
309
|
foreach ($clients as $client):
|
310
|
?>
|
311
|
<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
|
312
|
<td><?=htmlspecialchars($client['name']);?></td>
|
313
|
<td><?=$client['status'];?></td>
|
314
|
<td><?=$client['connect_time'];?></td>
|
315
|
<td>
|
316
|
<?php if (empty($client['local_host']) && empty($client['local_port'])): ?>
|
317
|
(pending)
|
318
|
<?php else: ?>
|
319
|
<?=$client['local_host'];?>:<?=$client['local_port'];?>
|
320
|
<?php endif; ?>
|
321
|
</td>
|
322
|
<td>
|
323
|
<?=$client['virtual_addr'];?>
|
324
|
<?php if (!empty($client['virtual_addr']) && !empty($client['virtual_addr6'])): ?>
|
325
|
<br />
|
326
|
<?php endif; ?>
|
327
|
<?=$client['virtual_addr6'];?>
|
328
|
</td>
|
329
|
<td>
|
330
|
<?php if (empty($client['remote_host']) && empty($client['remote_port'])): ?>
|
331
|
(pending)
|
332
|
<?php else: ?>
|
333
|
<?=$client['remote_host'];?>:<?=$client['remote_port'];?>
|
334
|
<?php endif; ?>
|
335
|
</td>
|
336
|
<td><?=format_bytes($client['bytes_sent']);?> / <?=format_bytes($client['bytes_recv']);?></td>
|
337
|
<td>
|
338
|
<table>
|
339
|
<tr>
|
340
|
<td>
|
341
|
<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
|
342
|
<?= get_service_status_icon($ssvc, false, true); ?>
|
343
|
<?= get_service_control_links($ssvc, true); ?>
|
344
|
</td>
|
345
|
</tr>
|
346
|
</table>
|
347
|
</td>
|
348
|
</tr>
|
349
|
<?php
|
350
|
endforeach;
|
351
|
?>
|
352
|
</tbody>
|
353
|
</table>
|
354
|
</div>
|
355
|
</div>
|
356
|
|
357
|
<?php
|
358
|
}
|
359
|
|
360
|
if ($DisplayNote) {
|
361
|
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."));
|
362
|
}
|
363
|
|
364
|
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
|
365
|
print_info_box(gettext("No OpenVPN instances defined."));
|
366
|
}
|
367
|
?>
|
368
|
</form>
|
369
|
|
370
|
<script type="text/javascript">
|
371
|
//<![CDATA[
|
372
|
|
373
|
function show_routes(id, buttonid) {
|
374
|
document.getElementById(buttonid).innerHTML='';
|
375
|
aodiv = document.getElementById(id);
|
376
|
aodiv.style.display = "block";
|
377
|
}
|
378
|
|
379
|
//]]>
|
380
|
</script>
|
381
|
|
382
|
<?php include("foot.inc"); ?>
|