Wireguard: added statistics

This commit is contained in:
bergware
2019-03-09 01:00:50 +01:00
parent a8c16b1e63
commit b8b940b793
2 changed files with 52 additions and 0 deletions
@@ -11,6 +11,9 @@
*/
?>
<?
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
require_once "$docroot/webGui/include/Helpers.php";
switch ($_POST['#case']) {
case 'keypair':
$private = '/var/tmp/privatekey';
@@ -42,5 +45,21 @@ case 'toggle':
if ($wg=='stop') exec("wg-quick down $port 2>/dev/null");
if ($wg=='start') exec("wg-quick up $port 2>/dev/null");
break;
case 'stats':
$port = $_POST['#port'];
$now = time(); $i = 0;
exec('wg show all latest-handshakes',$shake);
exec('wg show all transfer',$data);
$reply = $span = [];
foreach ($shake as $row) {
list($wg,$id,$time) = preg_split('/\s+/',$row);
if ($wg == $port) $span[] = $time ? $now - $time : 0;
}
foreach ($data as $row) {
list($wg,$id,$tx,$rx) = preg_split('/\s+/',$row);
if ($wg == $port) $reply[] = $span[$i++].';'.my_scale($rx,$unit,null,-1)." $unit;".my_scale($tx,$unit,null,-1)." $unit";
}
echo implode("\0",$reply);
break;
}
?>