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