1
|
<?php
|
2
|
/*
|
3
|
status_ovpenvpn.php
|
4
|
|
5
|
Copyright (C) 2010 Jim Pingle
|
6
|
Copyright (C) 2008 Shrew Soft Inc.
|
7
|
|
8
|
AJAX bits borrowed from diag_dump_states.php
|
9
|
Copyright (C) 2005 Scott Ullrich, Colin Smith
|
10
|
|
11
|
All rights reserved.
|
12
|
|
13
|
Redistribution and use in source and binary forms, with or without
|
14
|
modification, are permitted provided that the following conditions are met:
|
15
|
|
16
|
1. Redistributions of source code must retain the above copyright notice,
|
17
|
this list of conditions and the following disclaimer.
|
18
|
|
19
|
2. Redistributions in binary form must reproduce the above copyright
|
20
|
notice, this list of conditions and the following disclaimer in the
|
21
|
documentation and/or other materials provided with the distribution.
|
22
|
|
23
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
24
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
25
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
26
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
27
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
POSSIBILITY OF SUCH DAMAGE.
|
33
|
*/
|
34
|
/* DISABLE_PHP_LINT_CHECKING */
|
35
|
/*
|
36
|
pfSense_MODULE: openvpn
|
37
|
*/
|
38
|
|
39
|
##|+PRIV
|
40
|
##|*IDENT=page-status-openvpn
|
41
|
##|*NAME=Status: OpenVPN page
|
42
|
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
|
43
|
##|*MATCH=status_openvpn.php*
|
44
|
##|-PRIV
|
45
|
|
46
|
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
|
47
|
$shortcut_section = "openvpn";
|
48
|
|
49
|
require("guiconfig.inc");
|
50
|
require_once("openvpn.inc");
|
51
|
require_once("shortcuts.inc");
|
52
|
require_once("service-utils.inc");
|
53
|
|
54
|
/* Handle AJAX */
|
55
|
if($_GET['action']) {
|
56
|
if($_GET['action'] == "kill") {
|
57
|
$port = $_GET['port'];
|
58
|
$remipp = $_GET['remipp'];
|
59
|
if (!empty($port) and !empty($remipp)) {
|
60
|
$retval = kill_client($port, $remipp);
|
61
|
echo htmlentities("|{$port}|{$remipp}|{$retval}|");
|
62
|
} else {
|
63
|
echo gettext("invalid input");
|
64
|
}
|
65
|
exit;
|
66
|
}
|
67
|
}
|
68
|
|
69
|
|
70
|
function kill_client($port, $remipp) {
|
71
|
global $g;
|
72
|
|
73
|
//$tcpsrv = "tcp://127.0.0.1:{$port}";
|
74
|
$tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock";
|
75
|
$errval;
|
76
|
$errstr;
|
77
|
|
78
|
/* open a tcp connection to the management port of each server */
|
79
|
$fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1);
|
80
|
$killed = -1;
|
81
|
if ($fp) {
|
82
|
stream_set_timeout($fp, 1);
|
83
|
fputs($fp, "kill {$remipp}\n");
|
84
|
while (!feof($fp)) {
|
85
|
$line = fgets($fp, 1024);
|
86
|
|
87
|
$info = stream_get_meta_data($fp);
|
88
|
if ($info['timed_out'])
|
89
|
break;
|
90
|
|
91
|
/* parse header list line */
|
92
|
if (strpos($line, "INFO:") !== false)
|
93
|
continue;
|
94
|
if (strpos($line, "SUCCESS") !== false) {
|
95
|
$killed = 0;
|
96
|
}
|
97
|
break;
|
98
|
}
|
99
|
fclose($fp);
|
100
|
}
|
101
|
return $killed;
|
102
|
}
|
103
|
|
104
|
$servers = openvpn_get_active_servers();
|
105
|
$sk_servers = openvpn_get_active_servers("p2p");
|
106
|
$clients = openvpn_get_active_clients();
|
107
|
|
108
|
include("head.inc"); ?>
|
109
|
|
110
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
|
111
|
<?php include("fbegin.inc"); ?>
|
112
|
<form action="status_openvpn.php" method="get" name="iform">
|
113
|
<script type="text/javascript">
|
114
|
//<![CDATA[
|
115
|
function killClient(mport, remipp) {
|
116
|
var busy = function(index,icon) {
|
117
|
jQuery(icon).bind("onclick","");
|
118
|
jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
|
119
|
jQuery(icon).css("cursor","wait");
|
120
|
}
|
121
|
|
122
|
jQuery('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
|
123
|
|
124
|
jQuery.ajax(
|
125
|
"<?=$_SERVER['SCRIPT_NAME'];?>" +
|
126
|
"?action=kill&port=" + mport + "&remipp=" + remipp,
|
127
|
{ type: "get", complete: killComplete }
|
128
|
);
|
129
|
}
|
130
|
|
131
|
function killComplete(req) {
|
132
|
var values = req.responseText.split("|");
|
133
|
if(values[3] != "0") {
|
134
|
alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
|
135
|
return;
|
136
|
}
|
137
|
|
138
|
jQuery('tr[id="Client_Connections_r:' + values[1] + ":" + values[2] + '"]').each(
|
139
|
function(index,row) { jQuery(row).fadeOut(1000); }
|
140
|
);
|
141
|
|
142
|
jQuery('tr[id="Routing_Table_r:' + values[1] + ":" + values[2] + '"]').each(
|
143
|
function(index,row) { jQuery(row).fadeOut(1000); }
|
144
|
);
|
145
|
}
|
146
|
//]]>
|
147
|
</script>
|
148
|
<?php $i = 0; ?>
|
149
|
<?php foreach ($servers as $server): ?>
|
150
|
|
151
|
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
|
152
|
<tr>
|
153
|
<td colspan="6" class="listtopic">
|
154
|
<?=$server['name'];?> <?=gettext("Client connections"); ?>
|
155
|
</td>
|
156
|
</tr>
|
157
|
<tr>
|
158
|
<td>
|
159
|
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
|
160
|
<thead>
|
161
|
<tr>
|
162
|
<td class="listhdrr"><?=gettext("Common Name"); ?></td>
|
163
|
<td class="listhdrr"><?=gettext("Real Address"); ?></td>
|
164
|
<td class="listhdrr"><?=gettext("Virtual Address"); ?></td>
|
165
|
<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
|
166
|
<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
|
167
|
<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
|
168
|
</tr>
|
169
|
</thead>
|
170
|
<tfoot>
|
171
|
<tr>
|
172
|
<td colspan="2" class="list" height="12">
|
173
|
<table>
|
174
|
<tr>
|
175
|
<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
|
176
|
<td><?= get_service_status_icon($ssvc, true, true); ?></td>
|
177
|
<td><?= get_service_control_links($ssvc, true); ?></td>
|
178
|
</tr>
|
179
|
</table>
|
180
|
</td>
|
181
|
<td colspan="4" class="list" height="12"> </td>
|
182
|
</tr>
|
183
|
</tfoot>
|
184
|
<tbody>
|
185
|
<?php
|
186
|
$rowIndex = 0;
|
187
|
foreach ($server['conns'] as $conn):
|
188
|
$rowIndex++;
|
189
|
?>
|
190
|
<tr id='<?php echo "Client_Connections_r:{$server['mgmt']}:{$conn['remote_host']}"; ?>'>
|
191
|
<td class="listlr">
|
192
|
<?=$conn['common_name'];?>
|
193
|
</td>
|
194
|
<td class="listr">
|
195
|
<?=$conn['remote_host'];?>
|
196
|
</td>
|
197
|
<td class="listr">
|
198
|
<?=$conn['virtual_addr'];?>
|
199
|
</td>
|
200
|
<td class="listr">
|
201
|
<?=$conn['connect_time'];?>
|
202
|
</td>
|
203
|
<td class="listr">
|
204
|
<?=$conn['bytes_sent'];?>
|
205
|
</td>
|
206
|
<td class="listr">
|
207
|
<?=$conn['bytes_recv'];?>
|
208
|
</td>
|
209
|
<td class='list'>
|
210
|
<img src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif' height='17' width='17' border='0'
|
211
|
onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style='cursor:pointer;'
|
212
|
name='<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>'
|
213
|
title='<?php echo gettext("Kill client connection from") . ' ' . $conn['remote_host']; ?>' alt='' />
|
214
|
</td>
|
215
|
</tr>
|
216
|
|
217
|
<?php
|
218
|
endforeach;
|
219
|
if($rowIndex == 0) {
|
220
|
?>
|
221
|
<tr><td></td></tr>
|
222
|
<?php
|
223
|
}
|
224
|
?>
|
225
|
</tbody>
|
226
|
</table>
|
227
|
</td>
|
228
|
</tr>
|
229
|
</table>
|
230
|
<?php if (is_array($server['routes']) && count($server['routes'])): ?>
|
231
|
<div id="shroutebut-<?= $i ?>">
|
232
|
<input type="button" onclick="show_routes('tabroute-<?= $i ?>','shroutebut-<?= $i ?>')" value="<?php echo gettext("Show Routing Table"); ?>"></input> - <?= gettext("Display OpenVPN's internal routing table for this server.") ?>
|
233
|
<br/><br/>
|
234
|
</div>
|
235
|
<table style="display: none; padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0" id="tabroute-<?= $i ?>">
|
236
|
<tr>
|
237
|
<td colspan="6" class="listtopic">
|
238
|
<?=$server['name'];?> <?=gettext("Routing Table"); ?>
|
239
|
</td>
|
240
|
</tr>
|
241
|
<tr>
|
242
|
<td>
|
243
|
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
|
244
|
<thead>
|
245
|
<tr>
|
246
|
<td class="listhdrr"><?=gettext("Common Name"); ?></td>
|
247
|
<td class="listhdrr"><?=gettext("Real Address"); ?></td>
|
248
|
<td class="listhdrr"><?=gettext("Target Network"); ?></td>
|
249
|
<td class="listhdrr"><?=gettext("Last Used"); ?></td>
|
250
|
</tr>
|
251
|
</thead>
|
252
|
<tfoot>
|
253
|
<tr>
|
254
|
<td colspan="6" class="list" height="12"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
|
255
|
</tr>
|
256
|
</tfoot>
|
257
|
<tbody>
|
258
|
<?php
|
259
|
$rowIndex = 0;
|
260
|
foreach ($server['routes'] as $conn):
|
261
|
$rowIndex++;
|
262
|
?>
|
263
|
<tr id='<?php echo "Routing_Table_r:{$server['mgmt']}:{$conn['remote_host']}"; ?>'>
|
264
|
<td class="listlr">
|
265
|
<?=$conn['common_name'];?>
|
266
|
</td>
|
267
|
<td class="listr">
|
268
|
<?=$conn['remote_host'];?>
|
269
|
</td>
|
270
|
<td class="listr">
|
271
|
<?=$conn['virtual_addr'];?>
|
272
|
</td>
|
273
|
<td class="listr">
|
274
|
<?=$conn['last_time'];?>
|
275
|
</td>
|
276
|
</tr>
|
277
|
|
278
|
<?php
|
279
|
endforeach;
|
280
|
if($rowIndex == 0) {
|
281
|
?>
|
282
|
<tr><td></td></tr>
|
283
|
<?php
|
284
|
}
|
285
|
?>
|
286
|
</tbody>
|
287
|
</table>
|
288
|
</td>
|
289
|
</tr>
|
290
|
</table>
|
291
|
<?php endif; ?>
|
292
|
<br/>
|
293
|
<?php $i++; ?>
|
294
|
<?php endforeach; ?>
|
295
|
<br/>
|
296
|
|
297
|
<?php if (!empty($sk_servers)) { ?>
|
298
|
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
|
299
|
<tr>
|
300
|
<td colspan="6" class="listtopic">
|
301
|
<?=gettext("Peer to Peer Server Instance Statistics"); ?>
|
302
|
</td>
|
303
|
</tr>
|
304
|
<tr>
|
305
|
<td>
|
306
|
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
|
307
|
<tr>
|
308
|
<td class="listhdrr"><?=gettext("Name"); ?></td>
|
309
|
<td class="listhdrr"><?=gettext("Status"); ?></td>
|
310
|
<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
|
311
|
<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
|
312
|
<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
|
313
|
<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
|
314
|
<td class="listhdrr"><?=gettext("Bytes Rcvd"); ?></td>
|
315
|
<td class="listhdrr"><?=gettext("Service"); ?></td>
|
316
|
</tr>
|
317
|
|
318
|
<?php foreach ($sk_servers as $sk_server): ?>
|
319
|
<tr id='<?php echo "Servers_r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>'>
|
320
|
<td class="listlr">
|
321
|
<?=$sk_server['name'];?>
|
322
|
</td>
|
323
|
<td class="listr">
|
324
|
<?=$sk_server['status'];?>
|
325
|
</td>
|
326
|
<td class="listr">
|
327
|
<?=$sk_server['connect_time'];?>
|
328
|
</td>
|
329
|
<td class="listr">
|
330
|
<?=$sk_server['virtual_addr'];?>
|
331
|
</td>
|
332
|
<td class="listr">
|
333
|
<?=$sk_server['remote_host'];?>
|
334
|
</td>
|
335
|
<td class="listr">
|
336
|
<?=$sk_server['bytes_sent'];?>
|
337
|
</td>
|
338
|
<td class="listr">
|
339
|
<?=$sk_server['bytes_recv'];?>
|
340
|
</td>
|
341
|
<td class="listr">
|
342
|
<table>
|
343
|
<tr>
|
344
|
<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
|
345
|
<td class="listr" align="center">
|
346
|
<?= get_service_status_icon($ssvc, false, true); ?>
|
347
|
</td>
|
348
|
<td><?= get_service_control_links($ssvc, true); ?></td>
|
349
|
</tr>
|
350
|
</table>
|
351
|
</td>
|
352
|
</tr>
|
353
|
<?php endforeach; ?>
|
354
|
</table>
|
355
|
</td>
|
356
|
</tr>
|
357
|
</table>
|
358
|
|
359
|
<?php
|
360
|
} ?>
|
361
|
<br/>
|
362
|
<?php if (!empty($clients)) { ?>
|
363
|
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
|
364
|
<tr>
|
365
|
<td colspan="6" class="listtopic">
|
366
|
<?=gettext("Client Instance Statistics"); ?>
|
367
|
</td>
|
368
|
</tr>
|
369
|
<tr>
|
370
|
<td>
|
371
|
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
|
372
|
<tr>
|
373
|
<td class="listhdrr"><?=gettext("Name"); ?></td>
|
374
|
<td class="listhdrr"><?=gettext("Status"); ?></td>
|
375
|
<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
|
376
|
<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
|
377
|
<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
|
378
|
<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
|
379
|
<td class="listhdrr"><?=gettext("Bytes Rcvd"); ?></td>
|
380
|
<td class="listhdrr"><?=gettext("Service"); ?></td>
|
381
|
</tr>
|
382
|
|
383
|
<?php foreach ($clients as $client): ?>
|
384
|
<tr id='<?php echo "Clients_r:{$client['port']}:{$client['vpnid']}"; ?>'>
|
385
|
<td class="listlr">
|
386
|
<?=$client['name'];?>
|
387
|
</td>
|
388
|
<td class="listr">
|
389
|
<?=$client['status'];?>
|
390
|
</td>
|
391
|
<td class="listr">
|
392
|
<?=$client['connect_time'];?>
|
393
|
</td>
|
394
|
<td class="listr">
|
395
|
<?=$client['virtual_addr'];?>
|
396
|
</td>
|
397
|
<td class="listr">
|
398
|
<?=$client['remote_host'];?>
|
399
|
</td>
|
400
|
<td class="listr">
|
401
|
<?=$client['bytes_sent'];?>
|
402
|
</td>
|
403
|
<td class="listr">
|
404
|
<?=$client['bytes_recv'];?>
|
405
|
</td>
|
406
|
<td class="listr" height="12">
|
407
|
<table>
|
408
|
<tr>
|
409
|
<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
|
410
|
<td class="listr" align="center">
|
411
|
<?= get_service_status_icon($ssvc, false, true); ?>
|
412
|
</td>
|
413
|
<td><?= get_service_control_links($ssvc, true); ?></td>
|
414
|
</tr>
|
415
|
</table>
|
416
|
</td>
|
417
|
</tr>
|
418
|
<?php endforeach; ?>
|
419
|
</table>
|
420
|
</td>
|
421
|
</tr>
|
422
|
</table>
|
423
|
|
424
|
<?php
|
425
|
}
|
426
|
|
427
|
if ($DisplayNote) {
|
428
|
echo "<br/><b>" . gettext("NOTE") . ":</b> " . gettext("If you have 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.");
|
429
|
}
|
430
|
|
431
|
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
|
432
|
echo gettext("No OpenVPN instance defined");
|
433
|
}
|
434
|
?>
|
435
|
|
436
|
</form>
|
437
|
|
438
|
<?php include("fend.inc"); ?>
|
439
|
<script type="text/javascript">
|
440
|
function show_routes(id, buttonid) {
|
441
|
document.getElementById(buttonid).innerHTML='';
|
442
|
aodiv = document.getElementById(id);
|
443
|
aodiv.style.display = "block";
|
444
|
}
|
445
|
</script>
|
446
|
|
447
|
</body>
|
448
|
</html>
|