Commit 20197cab authored by Ad Schellevis's avatar Ad Schellevis

(legacy) openvpn, fix kill client + some cleanups, closes...

(legacy) openvpn, fix kill client + some cleanups, closes https://github.com/opnsense/core/issues/687
parent fd4ad209
......@@ -51,12 +51,13 @@ function kill_client($port, $remipp) {
$line = fgets($fp, 1024);
$info = stream_get_meta_data($fp);
if ($info['timed_out'])
if ($info['timed_out']) {
break;
}
/* parse header list line */
if (strpos($line, "INFO:") !== false)
if (strpos($line, "INFO:") !== false) {
continue;
}
if (strpos($line, "SUCCESS") !== false) {
$killed = 0;
}
......@@ -73,9 +74,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$vpnid = 0;
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['action']) && $_POST['action'] == 'kill') {
$port = escapeshellarg($_POST['port']);
$remipp = escapeshellarg($_POST['remipp']);
if (!empty($port) and !empty($remipp)) {
$port = $_POST['port'];
$remipp = $_POST['remipp'];
if (!empty($port) && !empty($remipp)) {
$retval = kill_client($port, $remipp);
echo htmlentities("|{$port}|{$remipp}|{$retval}|");
} else {
......@@ -102,9 +103,10 @@ include("head.inc"); ?>
//<![CDATA[
$( document ).ready(function() {
// link kill buttons
$(".act_kill_client").click(function(){
var port = $(this).attr("data-client-port");
var ip = $(this).attr("data-client-ip");
$(".act_kill_client").click(function(event){
event.preventDefault();
var port = $(this).data("client-port");
var ip = $(this).data("client-ip");
$.post(window.location, {action: 'kill', port:port,remipp:ip}, function(data) {
location.reload();
});
......@@ -114,7 +116,7 @@ $( document ).ready(function() {
$("*[for='" + $(this).attr('id') + "']").toggleClass("hidden show");
});
// minimize all buttons, some pf the buttons come from the shared service
// minimize all buttons, some of the buttons come from the shared service
// functions, which outputs large buttons.
$(".btn").each(function(){
$(this).addClass("btn-xs");
......@@ -133,8 +135,9 @@ $( document ).ready(function() {
<form action="status_openvpn.php" method="get" name="iform">
<div class="table-responsive">
<table class="table table-striped">
<?php $i = 0; ?>
<?php foreach ($servers as $server): ?>
<?php
$i = 0;
foreach ($servers as $server): ?>
<tr>
<td colspan="8" class="listtopic">
<b><?=$server['name'];?> <?=gettext("Client connections"); ?></b>
......@@ -150,7 +153,8 @@ $( document ).ready(function() {
<td></td>
<td></td>
</tr>
<?php foreach ($server['conns'] as $conn): ?>
<?php
foreach ($server['conns'] as $conn): ?>
<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
<td><?=$conn['common_name'];?></td>
<td><?=$conn['remote_host'];?></td>
......@@ -160,15 +164,16 @@ $( document ).ready(function() {
<td><?=format_bytes($conn['bytes_recv']);?></td>
<td></td>
<td>
<a data-client-port="<?=$server['mgmt'];?>"
<button data-client-port="<?=$server['mgmt'];?>"
data-client-ip="<?=$conn['remote_host'];?>"
title="<?=gettext("Kill client connection from"). " ". $conn['remote_host'] ; ?>"
class="act_kill_client btn btn-default">
<span class="glyphicon glyphicon-remove"></span>
</a>
</button>
</td>
</tr>
<?php endforeach; ?>
<?php
endforeach; ?>
<tr>
<td colspan="2">
<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
......@@ -177,11 +182,12 @@ $( document ).ready(function() {
</td>
<td colspan="6">&nbsp;</td>
</tr>
<?php if (isset($server['routes']) && count($server['routes'])): ?>
<?php
if (isset($server['routes']) && count($server['routes'])): ?>
<tr>
<td colspan="8">
<button class="btn btn-default act_show_routes" type="button" id="showroutes_<?=$i?>"><i class="fa fa-info"></i>
<?php echo gettext("Show/Hide Routing Table"); ?>
<?=gettext("Show/Hide Routing Table"); ?>
</button>
<div class="hidden" for="showroutes_<?=$i?>">
<small>
......@@ -197,29 +203,31 @@ $( document ).ready(function() {
</tr>
</thead>
<tbody>
<?php foreach ($server['routes'] as $conn): ?>
<?php
foreach ($server['routes'] as $conn): ?>
<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
<td><?=$conn['common_name'];?></td>
<td><?=$conn['remote_host'];?></td>
<td><?=$conn['virtual_addr'];?></td>
<td><?=$conn['last_time'];?></td>
</tr>
<?php endforeach; ?>
<?php
endforeach; ?>
</tbody>
<tfoot>
<tr>
<td colspan="6"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
</tr>
</tfoot>
</tbody>
</table>
</div>
</td>
</tr>
<?php endif; ?>
<?php $i++; ?>
<?php endforeach; ?>
<?php if (!empty($sk_servers)) { ?>
<?php
endif;
$i++;
endforeach;
if (!empty($sk_servers)): ?>
<tr>
<td colspan="8" class="listtopic">
<b><?=gettext("Peer to Peer Server Instance Statistics"); ?></b>
......@@ -235,7 +243,8 @@ $( document ).ready(function() {
<td><?=gettext("Status"); ?></td>
<td></td>
</tr>
<?php foreach ($sk_servers as $sk_server): ?>
<?php
foreach ($sk_servers as $sk_server): ?>
<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
<td><?=$sk_server['name'];?></td>
<td><?=$sk_server['remote_host'];?></td>
......@@ -252,11 +261,12 @@ $( document ).ready(function() {
</div>
</td>
</tr>
<?php endforeach; ?>
<?php
} ?>
<?php
endforeach;
endif; ?>
<?php if (!empty($clients)) { ?>
<?php
if (!empty($clients)):?>
<tr>
<tr>
<td colspan="8" class="listtopic">
......@@ -273,7 +283,8 @@ $( document ).ready(function() {
<td><?=gettext("Status"); ?></td>
<td></td>
</tr>
<?php foreach ($clients as $client): ?>
<?php
foreach ($clients as $client): ?>
<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
<td><?=$client['name'];?></td>
<td><?=$client['connect_time'];?></td>
......@@ -290,15 +301,15 @@ $( document ).ready(function() {
</div>
</td>
</tr>
<?php endforeach; ?>
<?php
endforeach; ?>
</table>
</div>
<?php
}
<?php
endif;
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
echo gettext("No OpenVPN instance defined");
}
?>
}?>
</form>
</div>
</section>
......
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