mirror of
https://github.com/unraid/webgui.git
synced 2026-04-23 18:48:49 -05:00
Wireguard: added statistics
This commit is contained in:
@@ -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;
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user