🎨客户端列表新增客户端数据流量情况
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
"wireguard-ui/component"
|
||||
"wireguard-ui/http/param"
|
||||
"wireguard-ui/http/response"
|
||||
@@ -82,6 +83,25 @@ func (ClientApi) List(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
for i, v := range data {
|
||||
// 获取客户端链接信息
|
||||
peer, err := component.Wireguard().GetClientByPublicKey(v.Keys.PublicKey)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
var ipAllocation string
|
||||
for _, iaip := range peer.AllowedIPs {
|
||||
ipAllocation += iaip.String() + ","
|
||||
}
|
||||
data[i].DataTraffic = &vo.DataTraffic{
|
||||
Online: time.Since(peer.LastHandshakeTime).Minutes() < 3,
|
||||
ReceiveBytes: utils.FlowCalculation().Parse(peer.TransmitBytes),
|
||||
TransmitBytes: utils.FlowCalculation().Parse(peer.ReceiveBytes),
|
||||
ConnectEndpoint: ipAllocation,
|
||||
LastHandAt: peer.LastHandshakeTime.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
}
|
||||
|
||||
response.R(c).Paginate(data, total, p.Current, p.Size)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user