Compare commits

..

10 Commits

Author SHA1 Message Date
coward
ddef41dfca 添加 web/.env 2024-08-22 16:02:01 +08:00
6c6b40593e 🎨优化 2024-08-22 16:01:00 +08:00
45d83da5c7 🎨优化一哈 2024-08-22 15:37:21 +08:00
4fa123baa8 🎨优化一下子 2024-08-22 14:16:33 +08:00
c7a56b1dde 🐛修复一个牛逼的bug 2024-08-22 11:43:23 +08:00
37446ea958 🎨 2024-08-22 11:14:28 +08:00
1b28b196a0 🎨打印日志看输出 2024-08-21 16:39:30 +08:00
1a5ab341ab 🐛 2024-08-21 14:33:50 +08:00
299ec93199 🐛修复客户端链接列表的bug 2024-08-21 14:12:43 +08:00
32f61a0eef 🎨优化 2024-08-21 11:43:57 +08:00
13 changed files with 4906 additions and 37 deletions

56
.gitignore vendored
View File

@@ -233,33 +233,33 @@ fabric.properties
# vendor/ # vendor/
# Go workspace file # Go workspace file
go.work ./go.work
.idea ./.idea
web/.idea ./web/.idea
web/node_modules ./web/node_modules
web/.DS_Store ./web/.DS_Store
web/dist ./web/dist
web/dist-ssr ./web/dist-ssr
web/*.local ./web/*.local
web/.eslintcache ./web/.eslintcache
web/report.html ./web/report.html
web/vite.config.*.timestamp* ./web/vite.config.*.timestamp*
web/yarn.lock ./web/yarn.lock
web/npm-debug.log* ./web/npm-debug.log*
web/.pnpm-error.log* ./web/.pnpm-error.log*
web/.pnpm-debug.log ./web/.pnpm-debug.log
web/tests/**/coverage/ ./web/tests/**/coverage/
web/.vscode/ ./web/.vscode/
# Editor directories and files # Editor directories and files
web/*.suo ./web/*.suo
web/*.ntvs* ./web/*.ntvs*
web/*.njsproj ./web/*.njsproj
web/*.sln ./web/*.sln
web/tsconfig.tsbuildinfo ./web/tsconfig.tsbuildinfo
dist/assets dist/assets
dist/resource dist/resource
@@ -267,10 +267,10 @@ dist/favicon.png
dist/favicon.svg dist/favicon.svg
dist/index.html dist/index.html
template/tmp/* ./template/tmp/*
logs/* ./logs/*
app.yaml ./app.yaml
*.db ./*.db
.env ./.env
*.env ./*.env

View File

@@ -3,6 +3,7 @@ package api
import ( import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"strings"
"time" "time"
"wireguard-ui/component" "wireguard-ui/component"
"wireguard-ui/http/param" "wireguard-ui/http/param"
@@ -77,17 +78,25 @@ func (DashboardApi) ConnectionList(c *gin.Context) {
for _, iaip := range peer.AllowedIPs { for _, iaip := range peer.AllowedIPs {
ipAllocation += iaip.String() + "," ipAllocation += iaip.String() + ","
} }
// 去除一下最右边的逗号
if len(ipAllocation) > 0 {
ipAllocation = strings.TrimRight(ipAllocation, ",")
}
connections = append(connections, vo.DataTraffic{ connections = append(connections, vo.DataTraffic{
Name: clientInfo.Name, Name: clientInfo.Name,
Email: clientInfo.Email, Email: clientInfo.Email,
IpAllocation: clientInfo.IpAllocation, IpAllocation: ipAllocation,
Online: time.Since(peer.LastHandshakeTime).Minutes() < 3, Online: time.Since(peer.LastHandshakeTime).Minutes() < 3,
ReceiveBytes: utils.FlowCalculation().Parse(peer.TransmitBytes), ReceiveBytes: utils.FlowCalculation().Parse(peer.TransmitBytes),
TransmitBytes: utils.FlowCalculation().Parse(peer.ReceiveBytes), TransmitBytes: utils.FlowCalculation().Parse(peer.ReceiveBytes),
ConnectEndpoint: ipAllocation, ConnectEndpoint: peer.Endpoint.String(),
LastHandAt: peer.LastHandshakeTime.Format("2006-01-02 15:04:05"), LastHandAt: peer.LastHandshakeTime.Format("2006-01-02 15:04:05"),
}) })
} }
if len(connections) <= 0 {
connections = []vo.DataTraffic{}
}
response.R(c).OkWithData(connections) response.R(c).OkWithData(connections)
} }

View File

@@ -50,13 +50,13 @@ func Authorization() gin.HandlerFunc {
// 查询用户 // 查询用户
user, err := service.User().GetUserById(userClaims.ID) user, err := service.User().GetUserById(userClaims.ID)
if err != nil { if err != nil {
response.R(c).FailedWithError("用户不存在") response.R(c).AuthorizationFailed("用户不存在")
c.Abort() c.Abort()
return return
} }
if user.Status != constant.Enabled { if user.Status != constant.Enabled {
response.R(c).FailedWithError("用户状态异常,请联系管理员处理!") response.R(c).AuthorizationFailed("用户状态异常,请联系管理员处理!")
c.Abort() c.Abort()
return return
} }

View File

@@ -52,8 +52,8 @@ func RequestLog() gin.HandlerFunc {
method := c.Request.Method // 请求方式 method := c.Request.Method // 请求方式
ip := c.ClientIP() // 取出IP ip := c.ClientIP() // 取出IP
// 处理实际客户端IP // 处理实际客户端IP
if c.Request.Header.Get("X-Real-IP") != "" { if c.Request.Header.Get("X-Real-Ip") != "" {
ip = c.Request.Header.Get("X-Real-IP") // 这个是网关Nginx自定义的Header头 ip = c.Request.Header.Get("X-Real-Ip") // 这个是网关Nginx自定义的Header头
} else if c.Request.Header.Get("X-Forwarded-For") != "" { } else if c.Request.Header.Get("X-Forwarded-For") != "" {
ip = c.Request.Header.Get("X-Forwarded-For") // 这个是网关Nginx自定义的Header头 ip = c.Request.Header.Get("X-Forwarded-For") // 这个是网关Nginx自定义的Header头
} }

16
model/oauth_client.go Normal file
View File

@@ -0,0 +1,16 @@
package model
// AuthClient
// @description: 认证客户端
type AuthClient struct {
Base
Name string `json:"name" gorm:"type:varchar(255);not null;comment: '客户端名称'"`
ClientID string `json:"clientID" gorm:"type:varchar(255);not null;comment: '客户端ID'"`
ClientKey string `json:"clientKey" gorm:"type:varchar(255);not null;comment: '客户端key'"`
ExpireAt string `json:"expireAt" gorm:"type:varchar(255);not null;comment: '过期时间'"`
IsEnabled int `json:"isEnabled" gorm:"type:int(1);not null;comment: '是否启用'"`
}
func (AuthClient) TableName() string {
return "t_oauth_client"
}

View File

@@ -45,7 +45,7 @@ func (script) GenerateConfig() error {
Email: client.Email, Email: client.Email,
PublicKey: client.Keys.PublicKey, PublicKey: client.Keys.PublicKey,
PresharedKey: client.Keys.PresharedKey, PresharedKey: client.Keys.PresharedKey,
AllowedIPS: client.AllowedIpsStr, AllowedIPS: client.IpAllocationStr,
Endpoint: client.Endpoint, Endpoint: client.Endpoint,
CreateUser: client.CreateUser, CreateUser: client.CreateUser,
Enabled: cast.ToBool(client.Enabled), Enabled: cast.ToBool(client.Enabled),

3
web/.env Normal file
View File

@@ -0,0 +1,3 @@
VITE_TITLE = 'Wireguard-UI'
VITE_PORT = 3100

View File

@@ -37,7 +37,6 @@ export async function addDynamicRoutes() {
// 有token的情况 // 有token的情况
const userStore = useUserStore() const userStore = useUserStore()
try { try {
const permissionStore = usePermissionStore() const permissionStore = usePermissionStore()
!userStore.id && (await userStore.getUserInfo()) !userStore.id && (await userStore.getUserInfo())
@@ -49,8 +48,8 @@ export async function addDynamicRoutes() {
router.addRoute(NOT_FOUND_ROUTE) router.addRoute(NOT_FOUND_ROUTE)
} catch (error) { } catch (error) {
console.error(error) console.error(error)
$message.error('初始化用户信息失败: ' + error)
userStore.logout() userStore.logout()
$message.error('初始化用户信息失败: ' + error)
} }
} }

View File

@@ -6,6 +6,7 @@ export default {
component: Layout, component: Layout,
redirect: '/client', redirect: '/client',
meta: { meta: {
title: '客户端',
order: 2, order: 2,
}, },
children: [ children: [

View File

@@ -6,6 +6,7 @@ export default {
component: Layout, component: Layout,
redirect: '/setting', redirect: '/setting',
meta: { meta: {
title: '设置',
order: 3, order: 3,
}, },
children: [ children: [

View File

@@ -6,6 +6,7 @@ export default {
component: Layout, component: Layout,
redirect: '/user', redirect: '/user',
meta: { meta: {
title: '管理员',
order: 1, order: 1,
}, },
children: [ children: [

View File

@@ -6,6 +6,7 @@ export default {
component: Layout, component: Layout,
redirect: '/workbench', redirect: '/workbench',
meta: { meta: {
title: '工作台',
order: 0, order: 0,
}, },
children: [ children: [

4838
web/stats.html Normal file

File diff suppressed because one or more lines are too long