Files
lmvpn_server/internal/router/router.go
T
kevin c8b170d532 feat: VPN 管理后台新增系统环境检测面板
- 新增 /api/admin/vpn/diag 端点,检测 TUN 创建能力、root、CAP_NET_ADMIN、ip_forward、MASQUERADE
- Linux 下解析 /proc/self/status CapEff 位判断 CAP_NET_ADMIN,读 /proc/sys/net/ipv4/ip_forward,执行 iptables 检查 MASQUERADE
- 非 Linux 平台显示"仅 Linux 适用"
- 前端 VpnView 新增系统环境检测卡片,每项以勾叉标识并附修复提示
2026-07-06 14:27:42 +08:00

65 lines
1.8 KiB
Go

package router
import (
"net/http"
"strings"
"lmvpn/internal/handler"
"lmvpn/internal/middleware"
"lmvpn/internal/vpn"
"github.com/gin-gonic/gin"
)
func Setup(r *gin.Engine) {
r.GET("/ws", vpn.HandleWS)
r.POST("/api/login", middleware.LoginRateLimit(), handler.Login)
auth := r.Group("/api")
auth.Use(middleware.AuthMiddleware())
{
auth.GET("/me", handler.Me)
auth.PUT("/me/password", handler.ChangePassword)
auth.GET("/me/sessions", handler.ListMySessions)
auth.DELETE("/me/sessions/:sessionId", handler.RevokeMySession)
}
admin := r.Group("/api/admin")
admin.Use(middleware.AuthMiddleware(), middleware.AdminMiddleware())
{
admin.GET("/users/count", handler.GetUserCount)
admin.GET("/users", handler.ListUsers)
admin.POST("/users", handler.CreateUser)
admin.PUT("/users/:id", handler.UpdateUser)
admin.DELETE("/users/:id", handler.DeleteUser)
admin.DELETE("/users/:id/sessions", handler.AdminRevokeUserSessions)
admin.GET("/vpn/settings", handler.GetVpnSettings)
admin.PUT("/vpn/settings", handler.UpdateVpnSettings)
admin.GET("/vpn/status", handler.GetVpnStatus)
admin.GET("/vpn/diag", handler.GetVpnDiag)
admin.GET("/vpn/reservations", handler.ListVpnReservations)
admin.POST("/vpn/reservations", handler.CreateVpnReservation)
admin.DELETE("/vpn/reservations/:id", handler.DeleteVpnReservation)
}
distDir := http.Dir("./dist")
fs := http.FileServer(distDir)
r.NoRoute(func(c *gin.Context) {
path := c.Request.URL.Path
if strings.HasPrefix(path, "/api") || strings.HasPrefix(path, "/ws") {
c.JSON(http.StatusNotFound, gin.H{"error": "not found"})
return
}
f, err := distDir.Open(path)
if err != nil {
c.Header("Content-Type", "text/html")
c.File("./dist/index.html")
return
}
f.Close()
fs.ServeHTTP(c.Writer, c.Request)
})
}