Commit 768fdcc0 authored by Ad Schellevis's avatar Ad Schellevis

(dashboar, widgets) cleanup openvpn.widget.php, use status_openvpn.php for ajax action

parent c40b1824
<?php <?php
/* /*
Copyright (C) 2014 Deciso B.V. Copyright (C) 2014-2016 Deciso B.V.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
...@@ -26,259 +26,128 @@ ...@@ -26,259 +26,128 @@
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
$nocsrf = true;
require_once("guiconfig.inc"); require_once("guiconfig.inc");
require_once("openvpn.inc"); require_once("openvpn.inc");
/* Handle AJAX */
if ($_GET['action']) {
if ($_GET['action'] == "kill") {
$port = $_GET['port'];
$remipp = $_GET['remipp'];
if (!empty($port) and !empty($remipp)) {
$retval = kill_client($port, $remipp);
echo htmlentities("|{$port}|{$remipp}|{$retval}|");
} else {
echo gettext("invalid input");
}
exit;
}
}
function kill_client($port, $remipp)
{
//$tcpsrv = "tcp://127.0.0.1:{$port}";
$tcpsrv = "unix:///var/etc/openvpn/{$port}.sock";
$errval;
$errstr;
/* open a tcp connection to the management port of each server */
$fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1);
$killed = -1;
if ($fp) {
stream_set_timeout($fp, 1);
fputs($fp, "kill {$remipp}\n");
while (!feof($fp)) {
$line = fgets($fp, 1024);
$info = stream_get_meta_data($fp);
if ($info['timed_out']) {
break;
}
/* parse header list line */
if (strpos($line, "INFO:") !== false) {
continue;
}
if (strpos($line, "SUCCESS") !== false) {
$killed = 0;
}
break;
}
fclose($fp);
}
return $killed;
}
$servers = openvpn_get_active_servers(); $servers = openvpn_get_active_servers();
$sk_servers = openvpn_get_active_servers("p2p"); $sk_servers = openvpn_get_active_servers("p2p");
$clients = openvpn_get_active_clients(); $clients = openvpn_get_active_clients();
?> ?>
<br />
<script type="text/javascript"> <script type="text/javascript">
function killClient(mport, remipp) { $( document ).ready(function() {
var busy = function(index,icon) { // link kill buttons
jQuery(icon).bind("onclick",""); $(".act_kill_client").click(function(event){
jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif")); event.preventDefault();
jQuery(icon).css("cursor","wait"); var port = $(this).data("client-port");
} var ip = $(this).data("client-ip");
$.post('/status_openvpn.php', {action: 'kill', port:port, remipp:ip}, function(data) {
jQuery('span[name="i:' + mport + ":" + remipp + '"]').each(busy); location.reload();
});
jQuery.ajax( });
"<?=$_SERVER['SCRIPT_NAME'];?>" + });
"?action=kill&port=" + mport + "&remipp=" + remipp,
{ type: "get", complete: killComplete }
);
}
function killComplete(req) {
var values = req.responseText.split("|");
if(values[3] != "0") {
alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
return;
}
jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
function(index,row) { jQuery(row).fadeOut(1000); }
);
}
</script> </script>
<?php foreach ($servers as $server) : <?php
?> foreach ($servers as $server) :?>
<table class="table table-striped table-condensed">
<table class="table table-striped" style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0"> <thead>
<tr> <tr>
<td colspan="6" class="listtopic"> <th colspan="3">
<?=$server['name'];?> Client connections <?=$server['name'];?> <?=gettext("Client connections");?>
</td> </th>
</tr> </tr>
<tr> <tr>
<td> <th><?=gettext("Name/Time");?></th>
<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" sortableMultirow="2"> <th><?=gettext("Real/Virtual IP");?></th>
<tr> <th></th>
<td class="listhdrr">Name/Time</td>
<td class="listhdrr">Real/Virtual IP</td>
</tr>
<?php $rowIndex = 0;
foreach ($server['conns'] as $conn) :
$evenRowClass = $rowIndex % 2 ? " listMReven" : " listMRodd";
$rowIndex++;
?>
<tr name='<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>' class="<?=$evenRowClass?>">
<td class="listMRlr">
<?=$conn['common_name'];?>
</td>
<td class="listMRr">
<?=$conn['remote_host'];?>
</td>
<td class='listMR' rowspan="2">
<span class="glyphicon glyphicon-remove"
onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style='cursor:pointer;'
name='<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>'
title='Kill client connection from <?php echo $conn['remote_host']; ?>' alt='' ></span>
</td>
</tr>
<tr name='<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>' class="<?=$evenRowClass?>">
<td class="listMRlr">
<?=$conn['connect_time'];?>
</td>
<td class="listMRr">
<?=$conn['virtual_addr'];?>
</td>
</tr> </tr>
</thead>
<tbody>
<?php
$server['conns'] = array();
$server['conns'][] = array('remote_host' => 'xxx1', 'common_name' => 'cn1');
$server['conns'][] = array('remote_host' => 'xxx2', 'common_name' => 'cn2');
$server['conns'][] = array('remote_host' => 'xxx3', 'common_name' => 'cn3');
<?php foreach ($server['conns'] as $conn) :?>
endforeach; ?>
<tfoot>
<tr> <tr>
<td colspan="6" class="list" height="12"></td> <td><?=$conn['common_name'];?><br/><?=$conn['connect_time'];?></td>
</tr> <td><?=$conn['remote_host'];?><br/><?=$conn['virtual_addr'];?></td>
</tfoot> <td>
</table> <span class="glyphicon glyphicon-remove act_kill_client" data-client-port="<?=$server['mgmt'];?>"
data-client-ip="<?=$conn['remote_host'];?>"
style='cursor:pointer;'
title='Kill client connection from <?=$conn['remote_host']; ?>'>
</span>
</td> </td>
</tr> </tr>
</table>
<?php <?php
endforeach; ?> endforeach; ?>
<?php if (!empty($sk_servers)) { </tbody>
?> </table>
<table class="table table-striped" style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0"> <br/>
<?php
endforeach; ?>
<?php
if (!empty($sk_servers)):?>
<table class="table table-striped table-condensed">
<thead>
<tr> <tr>
<td colspan="6" class="listtopic"> <th colspan="3"><?= gettext('Peer to Peer Server Instance Statistics') ?></th>
<?= gettext('Peer to Peer Server Instance Statistics') ?>
</td>
</tr> </tr>
<tr> <tr>
<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"> <th><?= gettext('Name/Time') ?></th>
<tr> <th><?= gettext('Remote/Virtual IP') ?></th>
<td class="listhdrr"><?= gettext('Name/Time') ?></td> <th></th>
<td class="listhdrr"><?= gettext('Remote/Virtual IP') ?></td>
</tr> </tr>
</thead>
<?php foreach ($sk_servers as $sk_server) : <tbody>
?> <?php
<tr name='<?php echo "r:{$sk_server['port']}:{$sk_server['remote_host']}"; ?>'> foreach ($sk_servers as $sk_server) :?>
<td class="listlr"> <tr>
<?=$sk_server['name'];?> <td><?=$sk_server['name'];?><br/><?=$sk_server['connect_time'];?></td>
</td> <td><?=$sk_server['remote_host'];?><br/><?=$sk_server['virtual_addr'];?></td>
<td class="listr"> <td>
<?=$sk_server['remote_host'];?> <span class='glyphicon glyphicon-transfer <?=$sk_server['status'] == "up" ? "text-success" : "text-danger";?>'></span>
</td>
<td rowspan="2" align="center">
<?php
if ($sk_server['status'] == "up") {
/* tunnel is up */
$iconfn = "text-success";
} else {
/* tunnel is down */
$iconfn = "text-danger";
}
echo "<span class='glyphicon glyphicon-transfer ".$iconfn."'></span>";
?>
</td>
</tr>
<tr name='<?php echo "r:{$sk_server['port']}:{$sk_server['remote_host']}"; ?>'>
<td class="listlr">
<?=$sk_server['connect_time'];?>
</td>
<td class="listr">
<?=$sk_server['virtual_addr'];?>
</td> </td>
</tr> </tr>
<?php <?php
endforeach; ?> endforeach; ?>
</tbody>
</table> </table>
</tr> <br/>
</table>
<?php <?php
} ?> endif; ?>
<?php if (!empty($clients)) { <?php
?> if (!empty($clients)) {?>
<table class="table table-striped" style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0"> <table class="table table-striped table-condensed">
<thead>
<tr> <tr>
<td colspan="6" class="listtopic"> <th colspan="3"><?= gettext('Client Instance Statistics') ?></th>
<?= gettext('Client Instance Statistics') ?>
</td>
</tr> </tr>
<tr> <tr>
<table class="table table-striped" style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0"> <th><?= gettext('Name/Time') ?></th>
<tr> <th><?= gettext('Remote/Virtual IP') ?></th>
<td class="listhdrr"><?= gettext('Name/Time') ?></td> <th></th>
<td class="listhdrr"><?= gettext('Remote/Virtual IP') ?></td>
</tr> </tr>
</thead>
<tbody>
<?php foreach ($clients as $client) : <?php
?> foreach ($clients as $client) :?>
<tr name='<?php echo "r:{$client['port']}:{$client['remote_host']}"; ?>'> <tr>
<td class="listlr"> <td><?=$client['name'];?><br/><?=$client['connect_time'];?></td>
<?=$client['name'];?> <td><?=$client['remote_host'];?><br/><?=$client['virtual_addr'];?></td>
</td> <td>
<td class="listr"> <span class='glyphicon glyphicon-transfer <?=$client['status'] == "up" ? "text-success" : "text-danger" ;?>'></span>
<?=$client['remote_host'];?>
</td>
<td rowspan="2" align="center">
<?php
if ($client['status'] == "up") {
/* tunnel is up */
$iconfn = "text-success";
} else {
/* tunnel is down */
$iconfn = "text-danger";
}
echo "<span class='glyphicon glyphicon-transfer ".$iconfn."'></span>";
?>
</td>
</tr>
<tr name='<?php echo "r:{$client['port']}:{$client['remote_host']}"; ?>'>
<td class="listlr">
<?=$client['connect_time'];?>
</td>
<td class="listr">
<?=$client['virtual_addr'];?>
</td> </td>
</tr> </tr>
<?php <?php
endforeach; ?> endforeach; ?>
</tbody>
</table> </table>
</tr>
</table>
<?php <?php
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment