Compare commits
No commits in common. "v2" and "v2.3.0" have entirely different histories.
10
Dockerfile
10
Dockerfile
@ -1,9 +1,9 @@
|
||||
# 打包前端
|
||||
FROM node:18-alpine AS build-front
|
||||
FROM node:18-alpine as build-front
|
||||
|
||||
WORKDIR /front
|
||||
WORKDIR front
|
||||
COPY . .
|
||||
WORKDIR ./web
|
||||
WORKDIR web
|
||||
|
||||
RUN corepack enable
|
||||
RUN corepack prepare pnpm@8.6.10 --activate
|
||||
@ -13,7 +13,7 @@ RUN pnpm build
|
||||
RUN ls -lh && pwd
|
||||
|
||||
# 前后端集成打包
|
||||
FROM golang:alpine AS build-backend
|
||||
FROM golang:alpine as build-backend
|
||||
|
||||
RUN apk add upx
|
||||
WORKDIR /build
|
||||
@ -23,7 +23,7 @@ COPY --from=build-front /front/web/dist/ /build/dist
|
||||
ENV GO111MODULE=on
|
||||
ENV GOPROXY=https://goproxy.cn,direct
|
||||
|
||||
RUN go version && go build -ldflags="-s -w" -o wgui && upx -9 wgui
|
||||
RUN go build -ldflags="-s -w" -o wgui && upx -9 wgui
|
||||
|
||||
RUN ls -lh && chmod +x ./wgui
|
||||
|
||||
|
@ -3,16 +3,11 @@ package cron
|
||||
import (
|
||||
"gitee.ltd/lxh/logger/log"
|
||||
"github.com/go-co-op/gocron/v2"
|
||||
"github.com/spf13/cast"
|
||||
"os"
|
||||
"time"
|
||||
"wireguard-ui/cron/task"
|
||||
)
|
||||
|
||||
func Task() {
|
||||
if !cast.ToBool(os.Getenv("ENABLED_CRON")) {
|
||||
return
|
||||
}
|
||||
sch, err := gocron.NewScheduler(gocron.WithLocation(time.Local))
|
||||
if err != nil {
|
||||
log.Errorf("初始化定时任务失败")
|
||||
|
72
go.mod
72
go.mod
@ -1,25 +1,22 @@
|
||||
module wireguard-ui
|
||||
|
||||
go 1.22.7
|
||||
|
||||
toolchain go1.23.0
|
||||
go 1.21
|
||||
|
||||
require (
|
||||
gitee.ltd/lxh/logger v1.0.19
|
||||
gitee.ltd/lxh/logger v1.0.18
|
||||
github.com/charmbracelet/bubbles v0.20.0
|
||||
github.com/charmbracelet/lipgloss v0.13.0
|
||||
github.com/cowardmrx/go_aliyun_oss v1.0.7
|
||||
github.com/dustin/go-humanize v1.0.1
|
||||
github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203
|
||||
github.com/fsnotify/fsnotify v1.8.0
|
||||
github.com/gin-contrib/pprof v1.5.2
|
||||
github.com/fsnotify/fsnotify v1.7.0
|
||||
github.com/gin-gonic/gin v1.10.0
|
||||
github.com/glebarez/sqlite v1.11.0
|
||||
github.com/go-co-op/gocron/v2 v2.12.4
|
||||
github.com/go-playground/locales v0.14.1
|
||||
github.com/go-playground/universal-translator v0.18.1
|
||||
github.com/go-playground/validator/v10 v10.23.0
|
||||
github.com/go-resty/resty/v2 v2.15.3
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/go-resty/resty/v2 v2.13.1
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
|
||||
@ -43,34 +40,31 @@ require (
|
||||
github.com/aliyun/aliyun-oss-go-sdk v2.2.5+incompatible // indirect
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bytedance/sonic v1.12.9 // indirect
|
||||
github.com/bytedance/sonic/loader v0.2.2 // indirect
|
||||
github.com/bytedance/sonic v1.12.5 // indirect
|
||||
github.com/bytedance/sonic/loader v0.2.0 // indirect
|
||||
github.com/caarlos0/env/v6 v6.10.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/charmbracelet/bubbletea v1.1.0 // indirect
|
||||
github.com/charmbracelet/x/ansi v0.2.3 // indirect
|
||||
github.com/charmbracelet/x/term v0.2.0 // indirect
|
||||
github.com/cloudwego/base64x v0.1.5 // indirect
|
||||
github.com/cloudwego/base64x v0.1.4 // indirect
|
||||
github.com/cloudwego/iasm v0.2.0 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/dennwc/varint v1.0.0 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.7 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/glebarez/go-sqlite v1.21.2 // indirect
|
||||
github.com/go-kit/kit v0.12.0 // indirect
|
||||
github.com/go-kit/log v0.2.1 // indirect
|
||||
github.com/go-logfmt/logfmt v0.5.1 // indirect
|
||||
github.com/go-sql-driver/mysql v1.7.0 // indirect
|
||||
github.com/goccy/go-json v0.10.4 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/grafana/loki-client-go v0.0.0-20240913122146-e119d400c3a5 // indirect
|
||||
github.com/grafana/loki/pkg/push v0.0.0-20240912152814-63e84b476a9a // indirect
|
||||
github.com/grafana/regexp v0.0.0-20220304095617-2e8d9baf4ac2 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
|
||||
@ -78,18 +72,18 @@ require (
|
||||
github.com/jackc/puddle/v2 v2.2.1 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/joho/godotenv v1.5.1 // indirect
|
||||
github.com/jonboulle/clockwork v0.4.0 // indirect
|
||||
github.com/josharian/native v1.1.0 // indirect
|
||||
github.com/jpillora/backoff v1.0.0 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
|
||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/lixh00/loki-client-go v1.0.1 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-localereader v0.0.1 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
|
||||
github.com/mdlayher/genetlink v1.3.2 // indirect
|
||||
github.com/mdlayher/netlink v1.7.2 // indirect
|
||||
github.com/mdlayher/socket v0.4.1 // indirect
|
||||
@ -99,18 +93,16 @@ require (
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||
github.com/muesli/termenv v0.15.2 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
|
||||
github.com/panjf2000/ants/v2 v2.10.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/prometheus/client_golang v1.20.5 // indirect
|
||||
github.com/prometheus/client_model v0.6.1 // indirect
|
||||
github.com/prometheus/common v0.61.0 // indirect
|
||||
github.com/prometheus/procfs v0.15.1 // indirect
|
||||
github.com/prometheus/prometheus v0.35.0 // indirect
|
||||
github.com/prometheus/client_golang v1.13.0 // indirect
|
||||
github.com/prometheus/client_model v0.3.0 // indirect
|
||||
github.com/prometheus/common v0.37.0 // indirect
|
||||
github.com/prometheus/procfs v0.8.0 // indirect
|
||||
github.com/prometheus/prometheus v1.8.2-0.20201028100903-3245b3267b24 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
@ -120,29 +112,27 @@ require (
|
||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||
github.com/spf13/afero v1.11.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/stretchr/testify v1.10.0 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
|
||||
go.uber.org/atomic v1.11.0 // indirect
|
||||
go.uber.org/goleak v1.3.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
go.uber.org/zap v1.23.0 // indirect
|
||||
golang.org/x/arch v0.12.0 // indirect
|
||||
golang.org/x/arch v0.8.0 // indirect
|
||||
golang.org/x/image v0.18.0 // indirect
|
||||
golang.org/x/net v0.33.0 // indirect
|
||||
golang.org/x/oauth2 v0.24.0 // indirect
|
||||
golang.org/x/oauth2 v0.18.0 // indirect
|
||||
golang.org/x/sync v0.10.0 // indirect
|
||||
golang.org/x/sys v0.28.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
golang.org/x/time v0.8.0 // indirect
|
||||
golang.org/x/time v0.5.0 // indirect
|
||||
golang.zx2c4.com/wireguard v0.0.0-20230325221338-052af4a8072b // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
|
||||
google.golang.org/grpc v1.69.0 // indirect
|
||||
google.golang.org/protobuf v1.36.5 // indirect
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
|
||||
google.golang.org/grpc v1.62.1 // indirect
|
||||
google.golang.org/protobuf v1.34.1 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
modernc.org/libc v1.22.5 // indirect
|
||||
|
@ -3,10 +3,7 @@ package http
|
||||
import (
|
||||
"fmt"
|
||||
"gitee.ltd/lxh/logger/log"
|
||||
"github.com/gin-contrib/pprof"
|
||||
"github.com/spf13/cast"
|
||||
"net/http"
|
||||
"os"
|
||||
"wireguard-ui/config"
|
||||
"wireguard-ui/http/router"
|
||||
)
|
||||
@ -19,10 +16,6 @@ func Kernel() error {
|
||||
handler := router.InitRouter()
|
||||
addr := fmt.Sprintf(":%d", config.Config.Http.Port)
|
||||
|
||||
if cast.ToBool(os.Getenv("ENABLED_PPROF")) {
|
||||
pprof.Register(handler, "/monitoring")
|
||||
}
|
||||
|
||||
httpServer := http.Server{
|
||||
Addr: addr,
|
||||
Handler: handler,
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
// @description: 登陆相关API
|
||||
// @param r
|
||||
func ClientApi(r *gin.RouterGroup) {
|
||||
client := r.Group("client", middleware.RequestLog(), middleware.Authorization())
|
||||
client := r.Group("client", middleware.Authorization(), middleware.RequestLog())
|
||||
{
|
||||
client.POST("", api.Client().Save) // 新增/编辑客户端
|
||||
client.DELETE("/:id", api.Client().Delete) // 删除客户端
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
// @description: 控制台相关接口
|
||||
// @param r
|
||||
func DashboardApi(r *gin.RouterGroup) {
|
||||
dashboard := r.Group("dashboard", middleware.RequestLog(), middleware.Authorization())
|
||||
dashboard := r.Group("dashboard", middleware.Authorization(), middleware.RequestLog())
|
||||
{
|
||||
dashboard.GET("/request/list", api.Dashboard().List) // 请求日志
|
||||
dashboard.GET("/daily-poetry", api.Dashboard().DailyPoetry) // 每日诗词
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
// @description: 设置相关API
|
||||
// @param r
|
||||
func SettingApi(r *gin.RouterGroup) {
|
||||
setting := r.Group("setting", middleware.RequestLog(), middleware.Authorization())
|
||||
setting := r.Group("setting", middleware.Authorization(), middleware.RequestLog())
|
||||
{
|
||||
setting.POST("", api.Setting().Set) // 新增/编辑设置
|
||||
setting.DELETE("/:code", api.Setting().Delete) // 删除配置
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
// @description: 用户相关API
|
||||
// @param r
|
||||
func UserApi(r *gin.RouterGroup) {
|
||||
userApi := r.Group("user", middleware.RequestLog(), middleware.Authorization())
|
||||
userApi := r.Group("user", middleware.Authorization(), middleware.RequestLog())
|
||||
{
|
||||
userApi.GET("/info", api.User().GetLoginUser) // 获取当前登陆用户信息
|
||||
userApi.POST("", api.User().SaveUser) // 新增/编辑用户
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/glebarez/sqlite"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/spf13/viper"
|
||||
"golang.zx2c4.com/wireguard/wgctrl"
|
||||
@ -28,7 +27,6 @@ import (
|
||||
func Init() {
|
||||
initLogger() // 初始化日志
|
||||
initConfig() // 读取配置文件
|
||||
initEnv() // 加载环境变量文件
|
||||
initWireguard() // 初始化wireguard客户端
|
||||
initDatabase() // 初始化数据库
|
||||
initRedis() // 初始化redis
|
||||
@ -155,11 +153,3 @@ func initLogger() {
|
||||
FileEnable: true,
|
||||
})
|
||||
}
|
||||
|
||||
// initEnv
|
||||
// @description: 初始化环境变量
|
||||
func initEnv() {
|
||||
if err := godotenv.Load(".env"); err != nil {
|
||||
log.Errorf("加载.env文件失败: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
3
main.go
3
main.go
@ -8,7 +8,6 @@ import (
|
||||
"sort"
|
||||
"time"
|
||||
tui "wireguard-ui/cli"
|
||||
"wireguard-ui/cron"
|
||||
"wireguard-ui/http"
|
||||
"wireguard-ui/initialize"
|
||||
"wireguard-ui/script"
|
||||
@ -19,7 +18,7 @@ func init() {
|
||||
if err := script.New().Do(); err != nil {
|
||||
log.Errorf("执行脚本失败: %v", err.Error())
|
||||
}
|
||||
cron.Task()
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
16
model/oauth_client.go
Normal file
16
model/oauth_client.go
Normal 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"
|
||||
}
|
@ -22,3 +22,16 @@ type Client struct {
|
||||
func (Client) TableName() string {
|
||||
return "t_client"
|
||||
}
|
||||
|
||||
// Watcher
|
||||
// @description: 监听日志
|
||||
type Watcher struct {
|
||||
Base
|
||||
ClientId string `json:"clientId" gorm:"type:char(36);not null;comment:'客户端id'"`
|
||||
NotifyResult string `json:"notifyResult" gorm:"type:text;default null;comment:'通知结果'"`
|
||||
IsSend int `json:"isSend" gorm:"type:tinyint(1);default 0;comment:'是否已通知'"`
|
||||
}
|
||||
|
||||
func (Watcher) TableName() string {
|
||||
return "t_watcher"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user