feat(server): implement server management handlers and database schema

This commit is contained in:
Chang lue Tsen
2025-08-25 14:06:37 -04:00
parent 1ccbdc18b1
commit ad4f3df74e
108 changed files with 3152 additions and 718 deletions
@@ -0,0 +1,26 @@
package log
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Filter balance log
func FilterBalanceLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.FilterBalanceLogRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := log.NewFilterBalanceLogLogic(c.Request.Context(), svcCtx)
resp, err := l.FilterBalanceLog(&req)
result.HttpResult(c, resp, err)
}
}
@@ -0,0 +1,26 @@
package log
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Filter commission log
func FilterCommissionLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.FilterCommissionLogRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := log.NewFilterCommissionLogLogic(c.Request.Context(), svcCtx)
resp, err := l.FilterCommissionLog(&req)
result.HttpResult(c, resp, err)
}
}
@@ -0,0 +1,26 @@
package log
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Filter email log
func FilterEmailLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.FilterLogParams
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := log.NewFilterEmailLogLogic(c.Request.Context(), svcCtx)
resp, err := l.FilterEmailLog(&req)
result.HttpResult(c, resp, err)
}
}
@@ -0,0 +1,26 @@
package log
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Filter gift log
func FilterGiftLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.FilterGiftLogRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := log.NewFilterGiftLogLogic(c.Request.Context(), svcCtx)
resp, err := l.FilterGiftLog(&req)
result.HttpResult(c, resp, err)
}
}
@@ -0,0 +1,26 @@
package log
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Filter login log
func FilterLoginLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.FilterLoginLogRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := log.NewFilterLoginLogLogic(c.Request.Context(), svcCtx)
resp, err := l.FilterLoginLog(&req)
result.HttpResult(c, resp, err)
}
}
@@ -0,0 +1,26 @@
package log
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Filter mobile log
func FilterMobileLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.FilterLogParams
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := log.NewFilterMobileLogLogic(c.Request.Context(), svcCtx)
resp, err := l.FilterMobileLog(&req)
result.HttpResult(c, resp, err)
}
}
@@ -0,0 +1,26 @@
package log
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Filter register log
func FilterRegisterLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.FilterRegisterLogRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := log.NewFilterRegisterLogLogic(c.Request.Context(), svcCtx)
resp, err := l.FilterRegisterLog(&req)
result.HttpResult(c, resp, err)
}
}
@@ -0,0 +1,26 @@
package log
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Filter reset subscribe log
func FilterResetSubscribeLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.FilterResetSubscribeLogRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := log.NewFilterResetSubscribeLogLogic(c.Request.Context(), svcCtx)
resp, err := l.FilterResetSubscribeLog(&req)
result.HttpResult(c, resp, err)
}
}
@@ -0,0 +1,26 @@
package log
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Filter server traffic log
func FilterServerTrafficLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.FilterSubscribeTrafficRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := log.NewFilterServerTrafficLogLogic(c.Request.Context(), svcCtx)
resp, err := l.FilterServerTrafficLog(&req)
result.HttpResult(c, resp, err)
}
}
@@ -0,0 +1,26 @@
package log
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Filter subscribe log
func FilterSubscribeLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.FilterSubscribeLogRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := log.NewFilterSubscribeLogLogic(c.Request.Context(), svcCtx)
resp, err := l.FilterSubscribeLog(&req)
result.HttpResult(c, resp, err)
}
}
@@ -0,0 +1,26 @@
package log
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Filter user subscribe traffic log
func FilterUserSubscribeTrafficLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.FilterSubscribeTrafficRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := log.NewFilterUserSubscribeTrafficLogLogic(c.Request.Context(), svcCtx)
resp, err := l.FilterUserSubscribeTrafficLog(&req)
result.HttpResult(c, resp, err)
}
}
@@ -8,7 +8,7 @@ import (
"github.com/perfect-panel/server/pkg/result"
)
// Create node
// Create Node
func CreateNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.CreateNodeRequest
@@ -0,0 +1,26 @@
package server
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// CreateServerHandler Create Server
func CreateServerHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.CreateServerRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := server.NewCreateServerLogic(c.Request.Context(), svcCtx)
err := l.CreateServer(&req)
result.HttpResult(c, nil, err)
}
}
@@ -8,7 +8,7 @@ import (
"github.com/perfect-panel/server/pkg/result"
)
// Delete node
// Delete Node
func DeleteNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.DeleteNodeRequest
@@ -0,0 +1,26 @@
package server
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Delete Server
func DeleteServerHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.DeleteServerRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := server.NewDeleteServerLogic(c.Request.Context(), svcCtx)
err := l.DeleteServer(&req)
result.HttpResult(c, nil, err)
}
}
@@ -0,0 +1,26 @@
package server
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Filter Node List
func FilterNodeListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.FilterNodeListRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := server.NewFilterNodeListLogic(c.Request.Context(), svcCtx)
resp, err := l.FilterNodeList(&req)
result.HttpResult(c, resp, err)
}
}
@@ -0,0 +1,26 @@
package server
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// FilterServerListHandler Filter Server List
func FilterServerListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.FilterServerListRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := server.NewFilterServerListLogic(c.Request.Context(), svcCtx)
resp, err := l.FilterServerList(&req)
result.HttpResult(c, resp, err)
}
}
@@ -0,0 +1,26 @@
package server
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Get Server Protocols
func GetServerProtocolsHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.GetServerProtocolsRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := server.NewGetServerProtocolsLogic(c.Request.Context(), svcCtx)
resp, err := l.GetServerProtocols(&req)
result.HttpResult(c, resp, err)
}
}
@@ -0,0 +1,26 @@
package server
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Toggle Node Status
func ToggleNodeStatusHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.ToggleNodeStatusRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := server.NewToggleNodeStatusLogic(c.Request.Context(), svcCtx)
err := l.ToggleNodeStatus(&req)
result.HttpResult(c, nil, err)
}
}
@@ -8,7 +8,7 @@ import (
"github.com/perfect-panel/server/pkg/result"
)
// Update node
// Update Node
func UpdateNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.UpdateNodeRequest
@@ -0,0 +1,26 @@
package server
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Update Server
func UpdateServerHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.UpdateServerRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := server.NewUpdateServerLogic(c.Request.Context(), svcCtx)
err := l.UpdateServer(&req)
result.HttpResult(c, nil, err)
}
}
@@ -1,8 +1,8 @@
package server
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
@@ -19,7 +19,7 @@ func BatchDeleteNodeGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context
return
}
l := server.NewBatchDeleteNodeGroupLogic(c.Request.Context(), svcCtx)
l := server_bak.NewBatchDeleteNodeGroupLogic(c.Request.Context(), svcCtx)
err := l.BatchDeleteNodeGroup(&req)
result.HttpResult(c, nil, err)
}
@@ -1,8 +1,8 @@
package server
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
@@ -19,7 +19,7 @@ func BatchDeleteNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return
}
l := server.NewBatchDeleteNodeLogic(c.Request.Context(), svcCtx)
l := server_bak.NewBatchDeleteNodeLogic(c.Request.Context(), svcCtx)
err := l.BatchDeleteNode(&req)
result.HttpResult(c, nil, err)
}
@@ -1,8 +1,8 @@
package server
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
@@ -19,7 +19,7 @@ func CreateNodeGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return
}
l := server.NewCreateNodeGroupLogic(c.Request.Context(), svcCtx)
l := server_bak.NewCreateNodeGroupLogic(c.Request.Context(), svcCtx)
err := l.CreateNodeGroup(&req)
result.HttpResult(c, nil, err)
}
@@ -0,0 +1,26 @@
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Create node
func CreateNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.CreateNodeRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := server_bak.NewCreateNodeLogic(c.Request.Context(), svcCtx)
err := l.CreateNode(&req)
result.HttpResult(c, nil, err)
}
}
@@ -1,8 +1,8 @@
package server
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
@@ -19,7 +19,7 @@ func CreateRuleGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return
}
l := server.NewCreateRuleGroupLogic(c.Request.Context(), svcCtx)
l := server_bak.NewCreateRuleGroupLogic(c.Request.Context(), svcCtx)
err := l.CreateRuleGroup(&req)
result.HttpResult(c, nil, err)
}
@@ -1,8 +1,8 @@
package server
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
@@ -19,7 +19,7 @@ func DeleteNodeGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return
}
l := server.NewDeleteNodeGroupLogic(c.Request.Context(), svcCtx)
l := server_bak.NewDeleteNodeGroupLogic(c.Request.Context(), svcCtx)
err := l.DeleteNodeGroup(&req)
result.HttpResult(c, nil, err)
}
@@ -0,0 +1,26 @@
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Delete node
func DeleteNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.DeleteNodeRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := server_bak.NewDeleteNodeLogic(c.Request.Context(), svcCtx)
err := l.DeleteNode(&req)
result.HttpResult(c, nil, err)
}
}
@@ -1,8 +1,8 @@
package server
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
@@ -19,7 +19,7 @@ func DeleteRuleGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return
}
l := server.NewDeleteRuleGroupLogic(c.Request.Context(), svcCtx)
l := server_bak.NewDeleteRuleGroupLogic(c.Request.Context(), svcCtx)
err := l.DeleteRuleGroup(&req)
result.HttpResult(c, nil, err)
}
@@ -1,8 +1,8 @@
package server
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
@@ -19,7 +19,7 @@ func GetNodeDetailHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return
}
l := server.NewGetNodeDetailLogic(c.Request.Context(), svcCtx)
l := server_bak.NewGetNodeDetailLogic(c.Request.Context(), svcCtx)
resp, err := l.GetNodeDetail(&req)
result.HttpResult(c, resp, err)
}
@@ -1,8 +1,8 @@
package server
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/pkg/result"
)
@@ -11,7 +11,7 @@ import (
func GetNodeGroupListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
l := server.NewGetNodeGroupListLogic(c.Request.Context(), svcCtx)
l := server_bak.NewGetNodeGroupListLogic(c.Request.Context(), svcCtx)
resp, err := l.GetNodeGroupList()
result.HttpResult(c, resp, err)
}
@@ -1,8 +1,8 @@
package server
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
@@ -19,7 +19,7 @@ func GetNodeListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return
}
l := server.NewGetNodeListLogic(c.Request.Context(), svcCtx)
l := server_bak.NewGetNodeListLogic(c.Request.Context(), svcCtx)
resp, err := l.GetNodeList(&req)
result.HttpResult(c, resp, err)
}
@@ -1,8 +1,8 @@
package server
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/pkg/result"
)
@@ -11,7 +11,7 @@ import (
func GetNodeTagListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
l := server.NewGetNodeTagListLogic(c.Request.Context(), svcCtx)
l := server_bak.NewGetNodeTagListLogic(c.Request.Context(), svcCtx)
resp, err := l.GetNodeTagList()
result.HttpResult(c, resp, err)
}
@@ -1,8 +1,8 @@
package server
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/pkg/result"
)
@@ -11,7 +11,7 @@ import (
func GetRuleGroupListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
l := server.NewGetRuleGroupListLogic(c.Request.Context(), svcCtx)
l := server_bak.NewGetRuleGroupListLogic(c.Request.Context(), svcCtx)
resp, err := l.GetRuleGroupList()
result.HttpResult(c, resp, err)
}
@@ -1,8 +1,8 @@
package server
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
@@ -19,7 +19,7 @@ func NodeSortHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return
}
l := server.NewNodeSortLogic(c.Request.Context(), svcCtx)
l := server_bak.NewNodeSortLogic(c.Request.Context(), svcCtx)
err := l.NodeSort(&req)
result.HttpResult(c, nil, err)
}
@@ -1,8 +1,8 @@
package server
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
@@ -19,7 +19,7 @@ func UpdateNodeGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return
}
l := server.NewUpdateNodeGroupLogic(c.Request.Context(), svcCtx)
l := server_bak.NewUpdateNodeGroupLogic(c.Request.Context(), svcCtx)
err := l.UpdateNodeGroup(&req)
result.HttpResult(c, nil, err)
}
@@ -0,0 +1,26 @@
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
)
// Update node
func UpdateNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) {
var req types.UpdateNodeRequest
_ = c.ShouldBind(&req)
validateErr := svcCtx.Validate(&req)
if validateErr != nil {
result.ParamErrorResult(c, validateErr)
return
}
l := server_bak.NewUpdateNodeLogic(c.Request.Context(), svcCtx)
err := l.UpdateNode(&req)
result.HttpResult(c, nil, err)
}
}
@@ -1,8 +1,8 @@
package server
package server_bak
import (
"github.com/gin-gonic/gin"
"github.com/perfect-panel/server/internal/logic/admin/server"
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/result"
@@ -19,7 +19,7 @@ func UpdateRuleGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
return
}
l := server.NewUpdateRuleGroupLogic(c.Request.Context(), svcCtx)
l := server_bak.NewUpdateRuleGroupLogic(c.Request.Context(), svcCtx)
err := l.UpdateRuleGroup(&req)
result.HttpResult(c, nil, err)
}
+53 -41
View File
@@ -189,8 +189,41 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
adminLogGroupRouter.Use(middleware.AuthMiddleware(serverCtx))
{
// Filter balance log
adminLogGroupRouter.GET("/balance/list", adminLog.FilterBalanceLogHandler(serverCtx))
// Filter commission log
adminLogGroupRouter.GET("/commission/list", adminLog.FilterCommissionLogHandler(serverCtx))
// Filter email log
adminLogGroupRouter.GET("/email/list", adminLog.FilterEmailLogHandler(serverCtx))
// Filter gift log
adminLogGroupRouter.GET("/gift/list", adminLog.FilterGiftLogHandler(serverCtx))
// Filter login log
adminLogGroupRouter.GET("/login/list", adminLog.FilterLoginLogHandler(serverCtx))
// Get message log list
adminLogGroupRouter.GET("/message/list", adminLog.GetMessageLogListHandler(serverCtx))
// Filter mobile log
adminLogGroupRouter.GET("/mobile/list", adminLog.FilterMobileLogHandler(serverCtx))
// Filter register log
adminLogGroupRouter.GET("/register/list", adminLog.FilterRegisterLogHandler(serverCtx))
// Filter server traffic log
adminLogGroupRouter.GET("/server/traffic/list", adminLog.FilterServerTrafficLogHandler(serverCtx))
// Filter subscribe log
adminLogGroupRouter.GET("/subscribe/list", adminLog.FilterSubscribeLogHandler(serverCtx))
// Filter reset subscribe log
adminLogGroupRouter.GET("/subscribe/reset/list", adminLog.FilterResetSubscribeLogHandler(serverCtx))
// Filter user subscribe traffic log
adminLogGroupRouter.GET("/subscribe/traffic/list", adminLog.FilterUserSubscribeTrafficLogHandler(serverCtx))
}
adminMarketingGroupRouter := router.Group("/v1/admin/marketing")
@@ -251,56 +284,35 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
adminServerGroupRouter.Use(middleware.AuthMiddleware(serverCtx))
{
// Update node
adminServerGroupRouter.PUT("/", adminServer.UpdateNodeHandler(serverCtx))
// Create Server
adminServerGroupRouter.POST("/create", adminServer.CreateServerHandler(serverCtx))
// Create node
adminServerGroupRouter.POST("/", adminServer.CreateNodeHandler(serverCtx))
// Delete Server
adminServerGroupRouter.POST("/delete", adminServer.DeleteServerHandler(serverCtx))
// Delete node
adminServerGroupRouter.DELETE("/", adminServer.DeleteNodeHandler(serverCtx))
// Filter Server List
adminServerGroupRouter.GET("/list", adminServer.FilterServerListHandler(serverCtx))
// Batch delete node
adminServerGroupRouter.DELETE("/batch", adminServer.BatchDeleteNodeHandler(serverCtx))
// Create Node
adminServerGroupRouter.POST("/node/create", adminServer.CreateNodeHandler(serverCtx))
// Get node detail
adminServerGroupRouter.GET("/detail", adminServer.GetNodeDetailHandler(serverCtx))
// Delete Node
adminServerGroupRouter.POST("/node/delete", adminServer.DeleteNodeHandler(serverCtx))
// Create node group
adminServerGroupRouter.POST("/group", adminServer.CreateNodeGroupHandler(serverCtx))
// Filter Node List
adminServerGroupRouter.GET("/node/list", adminServer.FilterNodeListHandler(serverCtx))
// Update node group
adminServerGroupRouter.PUT("/group", adminServer.UpdateNodeGroupHandler(serverCtx))
// Toggle Node Status
adminServerGroupRouter.POST("/node/status/toggle", adminServer.ToggleNodeStatusHandler(serverCtx))
// Delete node group
adminServerGroupRouter.DELETE("/group", adminServer.DeleteNodeGroupHandler(serverCtx))
// Update Node
adminServerGroupRouter.POST("/node/update", adminServer.UpdateNodeHandler(serverCtx))
// Batch delete node group
adminServerGroupRouter.DELETE("/group/batch", adminServer.BatchDeleteNodeGroupHandler(serverCtx))
// Get Server Protocols
adminServerGroupRouter.GET("/protocols", adminServer.GetServerProtocolsHandler(serverCtx))
// Get node group list
adminServerGroupRouter.GET("/group/list", adminServer.GetNodeGroupListHandler(serverCtx))
// Get node list
adminServerGroupRouter.GET("/list", adminServer.GetNodeListHandler(serverCtx))
// Create rule group
adminServerGroupRouter.POST("/rule_group", adminServer.CreateRuleGroupHandler(serverCtx))
// Update rule group
adminServerGroupRouter.PUT("/rule_group", adminServer.UpdateRuleGroupHandler(serverCtx))
// Delete rule group
adminServerGroupRouter.DELETE("/rule_group", adminServer.DeleteRuleGroupHandler(serverCtx))
// Get rule group list
adminServerGroupRouter.GET("/rule_group_list", adminServer.GetRuleGroupListHandler(serverCtx))
// Node sort
adminServerGroupRouter.POST("/sort", adminServer.NodeSortHandler(serverCtx))
// Get node tag list
adminServerGroupRouter.GET("/tag/list", adminServer.GetNodeTagListHandler(serverCtx))
// Update Server
adminServerGroupRouter.POST("/update", adminServer.UpdateServerHandler(serverCtx))
}
adminSubscribeGroupRouter := router.Group("/v1/admin/subscribe")
@@ -6,12 +6,9 @@ import (
"strings"
"time"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/pkg/errors"
)
type QueryServerTotalDataLogic struct {
@@ -42,121 +39,6 @@ func (l *QueryServerTotalDataLogic) QueryServerTotalData() (resp *types.ServerTo
UserTrafficRankingYesterday: make([]types.UserTrafficData, 0),
}
// Query node server status
servers, err := l.svcCtx.ServerModel.FindAllServer(l.ctx)
if err != nil {
l.Errorw("[QueryServerTotalDataLogic] FindAllServer error", logger.Field("error", err.Error()))
return nil, errors.Wrapf(err, "FindAllServer error: %v", err)
}
onlineServers, err := l.svcCtx.NodeCache.GetOnlineNodeStatusCount(l.ctx)
if err != nil {
l.Errorw("[QueryServerTotalDataLogic] GetOnlineNodeStatusCount error", logger.Field("error", err.Error()))
return nil, errors.Wrapf(err, "GetOnlineNodeStatusCount error: %v", err)
}
resp.OnlineServers = onlineServers
resp.OfflineServers = int64(len(servers) - int(onlineServers))
// 获取所有节点在线用户
allNodeOnlineUser, err := l.svcCtx.NodeCache.GetAllNodeOnlineUser(l.ctx)
if err != nil {
l.Errorw("[QueryServerTotalDataLogic] Get all node online user failed", logger.Field("error", err.Error()))
}
resp.OnlineUserIPs = int64(len(allNodeOnlineUser))
// 获取所有节点今日上传下载流量
allNodeUploadTraffic, err := l.svcCtx.NodeCache.GetAllNodeUploadTraffic(l.ctx)
if err != nil {
l.Errorw("[QueryServerTotalDataLogic] Get all node upload traffic failed", logger.Field("error", err.Error()))
}
resp.TodayUpload = allNodeUploadTraffic
allNodeDownloadTraffic, err := l.svcCtx.NodeCache.GetAllNodeDownloadTraffic(l.ctx)
if err != nil {
l.Errorw("[QueryServerTotalDataLogic] Get all node download traffic failed", logger.Field("error", err.Error()))
}
resp.TodayDownload = allNodeDownloadTraffic
// 获取节点流量排行榜 前10
nodeTrafficRankingToday, err := l.svcCtx.NodeCache.GetNodeTodayTotalTrafficRank(l.ctx, 10)
if err != nil {
l.Errorw("[QueryServerTotalDataLogic] Get node today total traffic rank failed", logger.Field("error", err.Error()))
}
if len(nodeTrafficRankingToday) > 0 {
var serverTrafficData []types.ServerTrafficData
for _, rank := range nodeTrafficRankingToday {
serverInfo, err := l.svcCtx.ServerModel.FindOne(l.ctx, rank.ID)
if err != nil {
l.Errorw("[QueryServerTotalDataLogic] FindOne error", logger.Field("error", err))
continue
}
serverTrafficData = append(serverTrafficData, types.ServerTrafficData{
ServerId: rank.ID,
Name: serverInfo.Name,
Upload: rank.Upload,
Download: rank.Download,
})
}
resp.ServerTrafficRankingToday = serverTrafficData
}
// 获取用户流量排行榜 前10
userTrafficRankingToday, err := l.svcCtx.NodeCache.GetUserTodayTotalTrafficRank(l.ctx, 10)
if err != nil {
l.Errorw("[QueryServerTotalDataLogic] Get user today total traffic rank failed", logger.Field("error", err.Error()))
}
if len(userTrafficRankingToday) > 0 {
var userTrafficData []types.UserTrafficData
for _, rank := range userTrafficRankingToday {
userTrafficData = append(userTrafficData, types.UserTrafficData{
SID: rank.SID,
Upload: rank.Upload,
Download: rank.Download,
})
}
resp.UserTrafficRankingToday = userTrafficData
}
// 获取昨日节点流量排行榜 前10
nodeTrafficRankingYesterday, err := l.svcCtx.NodeCache.GetYesterdayNodeTotalTrafficRank(l.ctx)
if err != nil {
l.Errorw("[QueryServerTotalDataLogic] Get yesterday node total traffic rank failed", logger.Field("error", err.Error()))
}
if len(nodeTrafficRankingYesterday) > 0 {
var serverTrafficData []types.ServerTrafficData
for _, rank := range nodeTrafficRankingYesterday {
serverTrafficData = append(serverTrafficData, types.ServerTrafficData{
ServerId: rank.ID,
Name: rank.Name,
Upload: rank.Upload,
Download: rank.Download,
})
}
resp.ServerTrafficRankingYesterday = serverTrafficData
}
// 获取昨日用户流量排行榜 前10
userTrafficRankingYesterday, err := l.svcCtx.NodeCache.GetYesterdayUserTotalTrafficRank(l.ctx)
if err != nil {
l.Errorw("[QueryServerTotalDataLogic] Get yesterday user total traffic rank failed", logger.Field("error", err.Error()))
}
if len(userTrafficRankingYesterday) > 0 {
var userTrafficData []types.UserTrafficData
for _, rank := range userTrafficRankingYesterday {
userTrafficData = append(userTrafficData, types.UserTrafficData{
SID: rank.SID,
Upload: rank.Upload,
Download: rank.Download,
})
}
resp.UserTrafficRankingYesterday = userTrafficData
}
// Query node traffic by monthly
nodeTraffic, err := l.svcCtx.TrafficLogModel.QueryTrafficByMonthly(l.ctx, time.Now())
if err != nil {
l.Errorw("[QueryServerTotalDataLogic] QueryTrafficByMonthly error", logger.Field("error", err.Error()))
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "QueryTrafficByMonthly error: %v", err.Error())
}
resp.MonthlyUpload = nodeTraffic.Upload
resp.MonthlyDownload = nodeTraffic.Download
return resp, nil
}
@@ -0,0 +1,64 @@
package log
import (
"context"
"github.com/perfect-panel/server/internal/model/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type FilterBalanceLogLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// NewFilterBalanceLogLogic Filter balance log
func NewFilterBalanceLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterBalanceLogLogic {
return &FilterBalanceLogLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *FilterBalanceLogLogic) FilterBalanceLog(req *types.FilterBalanceLogRequest) (resp *types.FilterBalanceLogResponse, err error) {
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
Page: req.Page,
Size: req.Size,
Type: log.TypeBalance.Uint8(),
Data: req.Date,
ObjectID: req.UserId,
})
if err != nil {
l.Errorw("[FilterBalanceLog] Query User Balance Log Error:", logger.Field("error", err.Error()))
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Query User Balance Log Error")
}
list := make([]types.BalanceLog, 0)
for _, datum := range data {
var content log.Balance
if err = content.Unmarshal([]byte(datum.Content)); err != nil {
l.Errorf("[QueryUserBalanceLog] unmarshal balance log content failed: %v", err.Error())
continue
}
list = append(list, types.BalanceLog{
UserId: datum.ObjectID,
Amount: content.Amount,
Type: content.Type,
OrderId: content.OrderId,
Balance: content.Balance,
Timestamp: content.Timestamp,
})
}
return &types.FilterBalanceLogResponse{
Total: total,
List: list,
}, nil
}
@@ -0,0 +1,61 @@
package log
import (
"context"
"github.com/perfect-panel/server/internal/model/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type FilterCommissionLogLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// NewFilterCommissionLogLogic Filter commission log
func NewFilterCommissionLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterCommissionLogLogic {
return &FilterCommissionLogLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *FilterCommissionLogLogic) FilterCommissionLog(req *types.FilterCommissionLogRequest) (resp *types.FilterCommissionLogResponse, err error) {
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
Page: req.Page,
Size: req.Size,
Data: req.Date,
Type: log.TypeCommission.Uint8(),
ObjectID: req.UserId,
})
if err != nil {
l.Errorw("Query User Commission Log failed", logger.Field("error", err.Error()))
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Query User Commission Log failed")
}
var list []types.CommissionLog
for _, datum := range data {
var content log.Commission
if err = content.Unmarshal([]byte(datum.Content)); err != nil {
l.Errorf("unmarshal commission log content failed: %v", err.Error())
continue
}
list = append(list, types.CommissionLog{
UserId: datum.ObjectID,
Type: content.Type,
Amount: content.Amount,
OrderNo: content.OrderNo,
CreatedAt: content.CreatedAt,
})
}
return &types.FilterCommissionLogResponse{
Total: total,
List: list,
}, nil
}
@@ -0,0 +1,68 @@
package log
import (
"context"
"github.com/perfect-panel/server/internal/model/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type FilterEmailLogLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// NewFilterEmailLogLogic Filter email log
func NewFilterEmailLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterEmailLogLogic {
return &FilterEmailLogLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *FilterEmailLogLogic) FilterEmailLog(req *types.FilterLogParams) (resp *types.FilterEmailLogResponse, err error) {
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
Page: req.Page,
Size: req.Size,
Type: log.TypeEmailMessage.Uint8(),
Data: req.Date,
Search: req.Search,
})
if err != nil {
l.Errorf("[FilterEmailLog] failed to filter system log: %v", err.Error())
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "failed to filter system log: %v", err.Error())
}
var list []types.MessageLog
for _, datum := range data {
var content log.Message
err = content.Unmarshal([]byte(datum.Content))
if err != nil {
l.Errorf("[FilterEmailLog] failed to unmarshal content: %v", err.Error())
continue
}
list = append(list, types.MessageLog{
Id: datum.Id,
Type: datum.Type,
Platform: content.Platform,
To: content.To,
Subject: content.Subject,
Content: content.Content,
Status: content.Status,
CreatedAt: datum.CreatedAt.UnixMilli(),
})
}
return &types.FilterEmailLogResponse{
Total: total,
List: list,
}, nil
}
@@ -0,0 +1,68 @@
package log
import (
"context"
"github.com/perfect-panel/server/internal/model/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type FilterGiftLogLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// Filter gift log
func NewFilterGiftLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterGiftLogLogic {
return &FilterGiftLogLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *FilterGiftLogLogic) FilterGiftLog(req *types.FilterGiftLogRequest) (resp *types.FilterGiftLogResponse, err error) {
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
Page: req.Page,
Size: req.Size,
Type: log.TypeGift.Uint8(),
ObjectID: req.UserId,
Data: req.Date,
Search: req.Search,
})
if err != nil {
l.Errorf("[FilterGiftLog] failed to filter system log: %v", err.Error())
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "failed to filter system log: %v", err.Error())
}
var list []types.GiftLog
for _, datum := range data {
var content log.Gift
err = content.Unmarshal([]byte(datum.Content))
if err != nil {
l.Errorf("[FilterGiftLog] failed to unmarshal content: %v", err.Error())
continue
}
list = append(list, types.GiftLog{
Type: content.Type,
UserId: datum.ObjectID,
OrderNo: content.OrderNo,
SubscribeId: content.SubscribeId,
Amount: content.Amount,
Balance: content.Balance,
Remark: content.Remark,
CreatedAt: content.CreatedAt,
})
}
return &types.FilterGiftLogResponse{
Total: total,
List: list,
}, nil
}
@@ -0,0 +1,65 @@
package log
import (
"context"
"github.com/perfect-panel/server/internal/model/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type FilterLoginLogLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// NewFilterLoginLogLogic Filter login log
func NewFilterLoginLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterLoginLogLogic {
return &FilterLoginLogLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *FilterLoginLogLogic) FilterLoginLog(req *types.FilterLoginLogRequest) (resp *types.FilterLoginLogResponse, err error) {
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
Page: req.Page,
Size: req.Size,
Type: log.TypeLogin.Uint8(),
ObjectID: req.UserId,
Data: req.Date,
Search: req.Search,
})
if err != nil {
l.Errorf("[FilterLoginLog] failed to filter system log: %v", err.Error())
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "failed to filter system log: %v", err.Error())
}
var list []types.LoginLog
for _, datum := range data {
var item log.Login
err = item.Unmarshal([]byte(datum.Content))
if err != nil {
l.Errorf("[FilterLoginLog] failed to unmarshal content: %v", err.Error())
continue
}
list = append(list, types.LoginLog{
UserId: datum.ObjectID,
Method: item.Method,
LoginIP: item.LoginIP,
UserAgent: item.UserAgent,
Success: item.Success,
LoginTime: item.LoginTime,
})
}
return &types.FilterLoginLogResponse{
Total: total,
List: list,
}, nil
}
@@ -0,0 +1,68 @@
package log
import (
"context"
"github.com/perfect-panel/server/internal/model/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type FilterMobileLogLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// Filter mobile log
func NewFilterMobileLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterMobileLogLogic {
return &FilterMobileLogLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *FilterMobileLogLogic) FilterMobileLog(req *types.FilterLogParams) (resp *types.FilterMobileLogResponse, err error) {
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
Page: req.Page,
Size: req.Size,
Type: log.TypeMobileMessage.Uint8(),
Data: req.Date,
Search: req.Search,
})
if err != nil {
l.Errorf("[FilterMobileLog] failed to filter system log: %v", err.Error())
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "failed to filter system log: %v", err.Error())
}
var list []types.MessageLog
for _, datum := range data {
var content log.Message
err = content.Unmarshal([]byte(datum.Content))
if err != nil {
l.Errorf("[FilterMobileLog] failed to unmarshal content: %v", err.Error())
continue
}
list = append(list, types.MessageLog{
Id: datum.Id,
Type: datum.Type,
Platform: content.Platform,
To: content.To,
Subject: content.Subject,
Content: content.Content,
Status: content.Status,
CreatedAt: datum.CreatedAt.UnixMilli(),
})
}
return &types.FilterMobileLogResponse{
Total: total,
List: list,
}, nil
}
@@ -0,0 +1,66 @@
package log
import (
"context"
"github.com/perfect-panel/server/internal/model/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type FilterRegisterLogLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// Filter register log
func NewFilterRegisterLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterRegisterLogLogic {
return &FilterRegisterLogLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *FilterRegisterLogLogic) FilterRegisterLog(req *types.FilterRegisterLogRequest) (resp *types.FilterRegisterLogResponse, err error) {
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
Page: req.Page,
Size: req.Size,
Type: log.TypeRegister.Uint8(),
ObjectID: req.UserId,
Data: req.Date,
Search: req.Search,
})
if err != nil {
l.Errorf("[FilterRegisterLog] failed to filter system log: %v", err.Error())
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "failed to filter system log: %v", err.Error())
}
var list []types.RegisterLog
for _, datum := range data {
var item log.Register
err = item.Unmarshal([]byte(datum.Content))
if err != nil {
l.Errorf("[FilterLoginLog] failed to unmarshal content: %v", err.Error())
continue
}
list = append(list, types.RegisterLog{
UserId: datum.ObjectID,
AuthMethod: item.AuthMethod,
Identifier: item.Identifier,
RegisterIP: item.RegisterIP,
UserAgent: item.UserAgent,
RegisterTime: item.RegisterTime,
})
}
return &types.FilterRegisterLogResponse{
List: list,
Total: total,
}, nil
}
@@ -0,0 +1,66 @@
package log
import (
"context"
"github.com/perfect-panel/server/internal/model/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type FilterResetSubscribeLogLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// NewFilterResetSubscribeLogLogic Filter reset subscribe log
func NewFilterResetSubscribeLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterResetSubscribeLogLogic {
return &FilterResetSubscribeLogLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *FilterResetSubscribeLogLogic) FilterResetSubscribeLog(req *types.FilterResetSubscribeLogRequest) (resp *types.FilterResetSubscribeLogResponse, err error) {
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
Page: req.Page,
Size: req.Size,
Type: log.TypeRegister.Uint8(),
ObjectID: req.UserSubscribeId,
Data: req.Date,
Search: req.Search,
})
if err != nil {
l.Errorf("[FilterResetSubscribeLog] failed to filter system log: %v", err.Error())
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "failed to filter system log: %v", err.Error())
}
var list []types.ResetSubscribeLog
for _, item := range data {
var content log.ResetSubscribe
err = content.Unmarshal([]byte(item.Content))
if err != nil {
l.Errorf("[FilterResetSubscribeLog] failed to unmarshal content: %v", err.Error())
continue
}
list = append(list, types.ResetSubscribeLog{
Type: content.Type,
UserId: content.UserId,
UserSubscribeId: item.ObjectID,
OrderNo: content.OrderNo,
ResetAt: content.ResetAt,
})
}
return &types.FilterResetSubscribeLogResponse{
List: list,
Total: total,
}, nil
}
@@ -0,0 +1,43 @@
package log
import (
"context"
"time"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
)
type FilterServerTrafficLogLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// NewFilterServerTrafficLogLogic Filter server traffic log
func NewFilterServerTrafficLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterServerTrafficLogLogic {
return &FilterServerTrafficLogLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *FilterServerTrafficLogLogic) FilterServerTrafficLog(req *types.FilterServerTrafficLogRequest) (resp *types.FilterServerTrafficLogResponse, err error) {
today := time.Now().Format("2006-01-02")
if req.Date == "" || req.Date == today {
return l.handlerToday(req)
} else {
return l.handlerSpecify(req)
}
}
func (l *FilterServerTrafficLogLogic) handlerToday(req *types.FilterServerTrafficLogRequest) (resp *types.FilterServerTrafficLogResponse, err error) {
return
}
func (l *FilterServerTrafficLogLogic) handlerSpecify(req *types.FilterServerTrafficLogRequest) (resp *types.FilterServerTrafficLogResponse, err error) {
return
}
@@ -0,0 +1,64 @@
package log
import (
"context"
"github.com/perfect-panel/server/internal/model/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type FilterSubscribeLogLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// Filter subscribe log
func NewFilterSubscribeLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterSubscribeLogLogic {
return &FilterSubscribeLogLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *FilterSubscribeLogLogic) FilterSubscribeLog(req *types.FilterSubscribeLogRequest) (resp *types.FilterSubscribeLogResponse, err error) {
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
Page: req.Page,
Size: req.Size,
Type: log.TypeSubscribe.Uint8(),
Data: req.Date,
ObjectID: req.UserId,
})
if err != nil {
l.Errorf("[FilterSubscribeLog] failed to filter system log: %v", err.Error())
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "failed to filter system log")
}
var list []types.SubscribeLog
for _, datum := range data {
var content log.Subscribe
err = content.Unmarshal([]byte(datum.Content))
if err != nil {
l.Errorf("[FilterSubscribeLog] failed to unmarshal content: %v", err.Error())
continue
}
list = append(list, types.SubscribeLog{
UserId: datum.ObjectID,
Token: content.Token,
UserAgent: content.UserAgent,
ClientIP: content.ClientIP,
UserSubscribeId: content.UserSubscribeId,
SubscribedAt: datum.CreatedAt.UnixMilli(),
})
}
return &types.FilterSubscribeLogResponse{
Total: total,
List: list,
}, nil
}
@@ -0,0 +1,30 @@
package log
import (
"context"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
)
type FilterUserSubscribeTrafficLogLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// NewFilterUserSubscribeTrafficLogLogic Filter user subscribe traffic log
func NewFilterUserSubscribeTrafficLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterUserSubscribeTrafficLogLogic {
return &FilterUserSubscribeTrafficLogLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *FilterUserSubscribeTrafficLogLogic) FilterUserSubscribeTrafficLog(req *types.FilterSubscribeTrafficRequest) (resp *types.FilterSubscribeTrafficResponse, err error) {
// todo: add your logic here and delete this line
return
}
+11 -94
View File
@@ -2,18 +2,13 @@ package server
import (
"context"
"encoding/json"
"strings"
"time"
"github.com/hibiken/asynq"
"github.com/perfect-panel/server/internal/model/server"
"github.com/perfect-panel/server/internal/model/node"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/tool"
"github.com/perfect-panel/server/pkg/xerr"
queue "github.com/perfect-panel/server/queue/types"
"github.com/pkg/errors"
)
@@ -23,6 +18,7 @@ type CreateNodeLogic struct {
svcCtx *svc.ServiceContext
}
// NewCreateNodeLogic Create Node
func NewCreateNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateNodeLogic {
return &CreateNodeLogic{
Logger: logger.WithContext(ctx),
@@ -32,97 +28,18 @@ func NewCreateNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Create
}
func (l *CreateNodeLogic) CreateNode(req *types.CreateNodeRequest) error {
config, err := json.Marshal(req.Config)
if err != nil {
return err
data := node.Node{
Name: req.Name,
Tags: tool.StringSliceToString(req.Tags),
Port: req.Port,
Address: req.Address,
ServerId: req.ServerId,
Protocol: req.Protocol,
}
var serverInfo server.Server
tool.DeepCopy(&serverInfo, req)
serverInfo.Config = string(config)
nodeRelay, err := json.Marshal(req.RelayNode)
if err != nil {
l.Errorw("[UpdateNode] Marshal RelayNode Error: ", logger.Field("error", err.Error()))
return err
}
if len(req.Tags) > 0 {
serverInfo.Tags = strings.Join(req.Tags, ",")
}
serverInfo.LastReportedAt = time.UnixMicro(1218124800)
serverInfo.City = req.City
serverInfo.Country = req.Country
serverInfo.RelayNode = string(nodeRelay)
if req.Protocol == "vless" {
var cfg types.Vless
if err = json.Unmarshal(config, &cfg); err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
}
if cfg.Security == "reality" && cfg.SecurityConfig.RealityPublicKey == "" {
public, private, err := tool.Curve25519Genkey(false, "")
if err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "generate curve25519 key error")
}
cfg.SecurityConfig.RealityPublicKey = public
cfg.SecurityConfig.RealityPrivateKey = private
cfg.SecurityConfig.RealityShortId = tool.GenerateShortID(private)
}
if cfg.SecurityConfig.RealityServerAddr == "" {
cfg.SecurityConfig.RealityServerAddr = cfg.SecurityConfig.SNI
}
if cfg.SecurityConfig.RealityServerPort == 0 {
cfg.SecurityConfig.RealityServerPort = 443
}
config, _ = json.Marshal(cfg)
serverInfo.Config = string(config)
} else if req.Protocol == "shadowsocks" {
var cfg types.Shadowsocks
if err = json.Unmarshal(config, &cfg); err != nil {
l.Errorf("[CreateNode] Unmarshal Shadowsocks Config Error: %v", err.Error())
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
}
if strings.Contains(cfg.Method, "2022") {
var length int
switch cfg.Method {
case "2022-blake3-aes-128-gcm":
length = 16
default:
length = 32
}
if len(cfg.ServerKey) != length {
cfg.ServerKey = tool.GenerateCipher(cfg.ServerKey, length)
}
}
config, _ = json.Marshal(cfg)
serverInfo.Config = string(config)
}
err = l.svcCtx.ServerModel.Insert(l.ctx, &serverInfo)
err := l.svcCtx.NodeModel.InsertNode(l.ctx, &data)
if err != nil {
l.Errorw("[CreateNode] Insert Database Error: ", logger.Field("error", err.Error()))
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "create server error: %v", err)
}
if req.City == "" || req.Country == "" {
// Marshal the task payload
payload, err := json.Marshal(queue.GetNodeCountry{
Protocol: serverInfo.Protocol,
ServerAddr: serverInfo.ServerAddr,
})
if err != nil {
l.Errorw("[GetNodeCountry]: Marshal Error", logger.Field("error", err.Error()))
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to marshal task payload")
}
// Create a queue task
task := asynq.NewTask(queue.ForthwithGetCountry, payload)
// Enqueue the task
taskInfo, err := l.svcCtx.Queue.Enqueue(task)
if err != nil {
l.Errorw("[GetNodeCountry]: Enqueue Error", logger.Field("error", err.Error()), logger.Field("payload", string(payload)))
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to enqueue task")
}
l.Infow("[GetNodeCountry]: Enqueue Success", logger.Field("taskID", taskInfo.ID), logger.Field("payload", string(payload)))
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "[CreateNode] Insert Database Error")
}
return nil
@@ -0,0 +1,111 @@
package server
import (
"context"
"strings"
"github.com/perfect-panel/server/internal/model/node"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/ip"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/tool"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type CreateServerLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// NewCreateServerLogic Create Server
func NewCreateServerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateServerLogic {
return &CreateServerLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CreateServerLogic) CreateServer(req *types.CreateServerRequest) error {
data := node.Server{
Name: req.Name,
Country: req.Country,
City: req.City,
Ratio: req.Ratio,
Address: req.Address,
Sort: req.Sort,
Protocols: "",
}
protocols := make([]node.Protocol, 0)
for _, item := range req.Protocols {
if item.Type == "" {
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.InvalidParams, "protocols type is empty"), "protocols type is empty")
}
var protocol node.Protocol
tool.DeepCopy(&protocol, item)
// VLESS Reality Key Generation
if protocol.Type == "vless" {
if protocol.Security == "reality" {
if protocol.RealityPublicKey == "" {
public, private, err := tool.Curve25519Genkey(false, "")
if err != nil {
l.Errorf("[CreateServer] Generate Reality Key Error: %v", err.Error())
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "generate reality key error: %v", err)
}
protocol.RealityPublicKey = public
protocol.RealityPrivateKey = private
protocol.RealityShortId = tool.GenerateShortID(private)
}
if protocol.RealityServerAddr == "" {
protocol.RealityServerAddr = protocol.SNI
}
if protocol.RealityServerPort == 0 {
protocol.RealityServerPort = 443
}
}
}
// ShadowSocks 2022 Key Generation
if protocol.Type == "shadowsocks" {
if strings.Contains(protocol.Cipher, "2022") {
var length int
switch protocol.Cipher {
case "2022-blake3-aes-128-gcm":
length = 16
default:
length = 32
}
if len(protocol.ServerKey) != length {
protocol.ServerKey = tool.GenerateCipher(protocol.ServerKey, length)
}
}
}
protocols = append(protocols, protocol)
}
err := data.MarshalProtocols(protocols)
if err != nil {
l.Errorf("[CreateServer] Marshal Protocols Error: %v", err.Error())
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.InvalidParams, "protocols marshal error"), "protocols marshal error: %v", err)
}
if data.City == "" && data.Country == "" {
// query server ip location
result, err := ip.GetRegionByIp(req.Address)
if err != nil {
l.Errorf("[CreateServer] GetRegionByIp Error: %v", err.Error())
} else {
data.City = result.City
data.Country = result.Country
}
}
err = l.svcCtx.NodeModel.InsertServer(l.ctx, &data)
if err != nil {
l.Errorf("[CreateServer] Insert Server error: %v", err.Error())
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "insert server error: %v", err)
}
return nil
}
+3 -27
View File
@@ -2,14 +2,12 @@ package server
import (
"context"
"github.com/perfect-panel/server/pkg/tool"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
"gorm.io/gorm"
)
type DeleteNodeLogic struct {
@@ -18,6 +16,7 @@ type DeleteNodeLogic struct {
svcCtx *svc.ServiceContext
}
// NewDeleteNodeLogic Delete Node
func NewDeleteNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteNodeLogic {
return &DeleteNodeLogic{
Logger: logger.WithContext(ctx),
@@ -27,33 +26,10 @@ func NewDeleteNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete
}
func (l *DeleteNodeLogic) DeleteNode(req *types.DeleteNodeRequest) error {
err := l.svcCtx.DB.Transaction(func(tx *gorm.DB) error {
// Delete server
err := l.svcCtx.ServerModel.Delete(l.ctx, req.Id, tx)
if err != nil {
return err
}
// Delete server to subscribe
subs, err := l.svcCtx.SubscribeModel.QuerySubscribeIdsByServerIdAndServerGroupId(l.ctx, req.Id, 0)
if err != nil {
l.Logger.Errorf("[DeleteNode] QuerySubscribeIdsByServerIdAndServerGroupId error: %v", err.Error())
return err
}
for _, sub := range subs {
servers := tool.StringToInt64Slice(sub.Server)
newServers := tool.RemoveElementBySlice(servers, req.Id)
sub.Server = tool.Int64SliceToString(newServers)
if err = l.svcCtx.SubscribeModel.Update(l.ctx, sub, tx); err != nil {
l.Logger.Errorf("[DeleteNode] UpdateSubscribe error: %v", err.Error())
return err
}
}
return nil
})
err := l.svcCtx.NodeModel.DeleteNode(l.ctx, req.Id)
if err != nil {
l.Errorw("[DeleteNode] Delete Database Error: ", logger.Field("error", err.Error()))
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseDeletedError), "delete server error: %v", err)
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseDeletedError), "[DeleteNode] Delete Database Error")
}
return nil
}
@@ -0,0 +1,30 @@
package server
import (
"context"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
)
type DeleteServerLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// NewDeleteServerLogic Delete Server
func NewDeleteServerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteServerLogic {
return &DeleteServerLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DeleteServerLogic) DeleteServer(req *types.DeleteServerRequest) error {
// todo: add your logic here and delete this line
return nil
}
@@ -0,0 +1,49 @@
package server
import (
"context"
"github.com/perfect-panel/server/internal/model/node"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/tool"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type FilterNodeListLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// NewFilterNodeListLogic Filter Node List
func NewFilterNodeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterNodeListLogic {
return &FilterNodeListLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *FilterNodeListLogic) FilterNodeList(req *types.FilterNodeListRequest) (resp *types.FilterNodeListResponse, err error) {
total, data, err := l.svcCtx.NodeModel.FilterNodeList(l.ctx, &node.FilterParams{
Page: req.Page,
Size: req.Size,
Search: req.Search,
})
if err != nil {
l.Errorw("[FilterNodeList] Query Database Error: ", logger.Field("error", err.Error()))
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "[FilterNodeList] Query Database Error")
}
list := make([]types.Node, 0)
tool.DeepCopy(&list, data)
return &types.FilterNodeListResponse{
List: list,
Total: total,
}, nil
}
@@ -0,0 +1,119 @@
package server
import (
"context"
"github.com/perfect-panel/server/internal/model/node"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/tool"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type FilterServerListLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// NewFilterServerListLogic Filter Server List
func NewFilterServerListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterServerListLogic {
return &FilterServerListLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *FilterServerListLogic) FilterServerList(req *types.FilterServerListRequest) (resp *types.FilterServerListResponse, err error) {
total, data, err := l.svcCtx.NodeModel.FilterServerList(l.ctx, &node.FilterParams{
Page: req.Page,
Size: req.Size,
Search: req.Search,
})
if err != nil {
l.Errorw("[FilterServerList] Query Database Error: ", logger.Field("error", err.Error()))
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "[FilterServerList] Query Database Error")
}
list := make([]types.Server, 0)
for _, datum := range data {
var server types.Server
tool.DeepCopy(&server, datum)
// handler protocols
var protocols []types.Protocol
dst, err := datum.UnmarshalProtocols()
if err != nil {
l.Errorf("[FilterServerList] UnmarshalProtocols Error: %s", err.Error())
continue
}
tool.DeepCopy(&protocols, dst)
server.Protocols = protocols
// handler status
server.Status = l.handlerServerStatus(datum.Id)
list = append(list, server)
}
return &types.FilterServerListResponse{
List: list,
Total: total,
}, nil
}
func (l *FilterServerListLogic) handlerServerStatus(id int64) types.ServerStatus {
var result types.ServerStatus
nodeStatus, err := l.svcCtx.NodeCache.GetNodeStatus(l.ctx, id)
if err != nil {
l.Errorw("[handlerServerStatus] GetNodeStatus Error: ", logger.Field("error", err.Error()), logger.Field("node_id", id))
return result
}
result = types.ServerStatus{
Mem: nodeStatus.Mem,
Cpu: nodeStatus.Cpu,
Disk: nodeStatus.Disk,
Online: make([]types.ServerOnlineUser, 0),
}
// parse online users
onlineUser, err := l.svcCtx.NodeCache.GetNodeOnlineUser(l.ctx, id)
if err != nil {
l.Errorw("[handlerServerStatus] GetNodeOnlineUser Error: ", logger.Field("error", err.Error()), logger.Field("node_id", id))
return result
}
var onlineList []types.ServerOnlineUser
var onlineMap = make(map[int64]types.ServerOnlineUser)
// group by user_id
for subId, info := range onlineUser {
data, err := l.svcCtx.UserModel.FindOneUserSubscribe(l.ctx, subId)
if err != nil {
l.Errorw("[handlerServerStatus] FindOneSubscribe Error: ", logger.Field("error", err.Error()))
continue
}
if online, exist := onlineMap[data.UserId]; !exist {
onlineMap[data.UserId] = types.ServerOnlineUser{
IP: info,
UserId: data.UserId,
Subscribe: data.Subscribe.Name,
SubscribeId: data.SubscribeId,
Traffic: data.Traffic,
ExpiredAt: data.ExpireTime.UnixMilli(),
}
} else {
online.IP = append(online.IP, info...)
onlineMap[data.UserId] = online
}
}
for _, online := range onlineMap {
onlineList = append(onlineList, online)
}
result.Online = onlineList
return result
}
@@ -0,0 +1,30 @@
package server
import (
"context"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
)
type GetServerProtocolsLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// Get Server Protocols
func NewGetServerProtocolsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetServerProtocolsLogic {
return &GetServerProtocolsLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetServerProtocolsLogic) GetServerProtocols(req *types.GetServerProtocolsRequest) (resp *types.GetServerProtocolsResponse, err error) {
// todo: add your logic here and delete this line
return
}
@@ -0,0 +1,43 @@
package server
import (
"context"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type ToggleNodeStatusLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// NewToggleNodeStatusLogic Toggle Node Status
func NewToggleNodeStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ToggleNodeStatusLogic {
return &ToggleNodeStatusLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ToggleNodeStatusLogic) ToggleNodeStatus(req *types.ToggleNodeStatusRequest) error {
data, err := l.svcCtx.NodeModel.FindOneNode(l.ctx, req.Id)
if err != nil {
l.Errorw("[ToggleNodeStatus] Query Database Error: ", logger.Field("error", err.Error()))
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "[ToggleNodeStatus] Query Database Error")
}
data.Enabled = req.Enable
err = l.svcCtx.NodeModel.UpdateNode(l.ctx, data)
if err != nil {
l.Errorw("[ToggleNodeStatus] Update Database Error: ", logger.Field("error", err.Error()))
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "[ToggleNodeStatus] Update Database Error")
}
return nil
}
+11 -104
View File
@@ -2,12 +2,6 @@ package server
import (
"context"
"encoding/json"
"strings"
"github.com/hibiken/asynq"
"github.com/perfect-panel/server/pkg/device"
queue "github.com/perfect-panel/server/queue/types"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
@@ -23,6 +17,7 @@ type UpdateNodeLogic struct {
svcCtx *svc.ServiceContext
}
// NewUpdateNodeLogic Update Node
func NewUpdateNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateNodeLogic {
return &UpdateNodeLogic{
Logger: logger.WithContext(ctx),
@@ -32,108 +27,20 @@ func NewUpdateNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Update
}
func (l *UpdateNodeLogic) UpdateNode(req *types.UpdateNodeRequest) error {
// Check server exist
nodeInfo, err := l.svcCtx.ServerModel.FindOne(l.ctx, req.Id)
data, err := l.svcCtx.NodeModel.FindOneNode(l.ctx, req.Id)
if err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find server error: %v", err)
l.Errorw("[UpdateNode] Query Database Error: ", logger.Field("error", err.Error()))
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "[UpdateNode] Query Database Error")
}
tool.DeepCopy(nodeInfo, req, tool.CopyWithIgnoreEmpty(false))
config, err := json.Marshal(req.Config)
if err != nil {
return err
}
nodeInfo.Config = string(config)
nodeRelay, err := json.Marshal(req.RelayNode)
if err != nil {
l.Errorw("[UpdateNode] Marshal RelayNode Error: ", logger.Field("error", err.Error()))
return err
}
// 处理Tags字段
switch {
case len(req.Tags) > 0:
// 有Tags,进行连接
nodeInfo.Tags = strings.Join(req.Tags, ",")
default:
// 空数组,清空Tags
nodeInfo.Tags = ""
}
nodeInfo.City = req.City
nodeInfo.Country = req.Country
nodeInfo.RelayNode = string(nodeRelay)
if req.Protocol == "vless" {
var cfg types.Vless
if err := json.Unmarshal(config, &cfg); err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
}
if cfg.Security == "reality" && cfg.SecurityConfig.RealityPublicKey == "" {
public, private, err := tool.Curve25519Genkey(false, "")
if err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "generate curve25519 key error")
}
cfg.SecurityConfig.RealityPublicKey = public
cfg.SecurityConfig.RealityPrivateKey = private
cfg.SecurityConfig.RealityShortId = tool.GenerateShortID(private)
}
if cfg.SecurityConfig.RealityServerAddr == "" {
cfg.SecurityConfig.RealityServerAddr = cfg.SecurityConfig.SNI
}
if cfg.SecurityConfig.RealityServerPort == 0 {
cfg.SecurityConfig.RealityServerPort = 443
}
config, _ = json.Marshal(cfg)
nodeInfo.Config = string(config)
} else if req.Protocol == "shadowsocks" {
var cfg types.Shadowsocks
if err = json.Unmarshal(config, &cfg); err != nil {
l.Errorf("[CreateNode] Unmarshal Shadowsocks Config Error: %v", err.Error())
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
}
if strings.Contains(cfg.Method, "2022") {
var length int
switch cfg.Method {
case "2022-blake3-aes-128-gcm":
length = 16
default:
length = 32
}
if len(cfg.ServerKey) != length {
cfg.ServerKey = tool.GenerateCipher(cfg.ServerKey, length)
}
}
config, _ = json.Marshal(cfg)
nodeInfo.Config = string(config)
}
err = l.svcCtx.ServerModel.Update(l.ctx, nodeInfo)
data.Name = req.Name
data.Tags = tool.StringSliceToString(req.Tags)
data.Port = req.Port
data.Address = req.Address
data.Protocol = req.Protocol
err = l.svcCtx.NodeModel.UpdateNode(l.ctx, data)
if err != nil {
l.Errorw("[UpdateNode] Update Database Error: ", logger.Field("error", err.Error()))
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "create server error: %v", err)
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "[UpdateNode] Update Database Error")
}
if req.City == "" || req.Country == "" {
// Marshal the task payload
payload, err := json.Marshal(queue.GetNodeCountry{
Protocol: nodeInfo.Protocol,
ServerAddr: nodeInfo.ServerAddr,
})
if err != nil {
l.Errorw("[GetNodeCountry]: Marshal Error", logger.Field("error", err.Error()))
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to marshal task payload")
}
// Create a queue task
task := asynq.NewTask(queue.ForthwithGetCountry, payload)
// Enqueue the task
taskInfo, err := l.svcCtx.Queue.Enqueue(task)
if err != nil {
l.Errorw("[GetNodeCountry]: Enqueue Error", logger.Field("error", err.Error()), logger.Field("payload", string(payload)))
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to enqueue task")
}
l.Infow("[GetNodeCountry]: Enqueue Success", logger.Field("taskID", taskInfo.ID), logger.Field("payload", string(payload)))
}
l.svcCtx.DeviceManager.Broadcast(device.SubscribeUpdate)
return nil
}
@@ -0,0 +1,115 @@
package server
import (
"context"
"strings"
"github.com/perfect-panel/server/internal/model/node"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/ip"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/tool"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type UpdateServerLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// NewUpdateServerLogic Update Server
func NewUpdateServerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateServerLogic {
return &UpdateServerLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UpdateServerLogic) UpdateServer(req *types.UpdateServerRequest) error {
data, err := l.svcCtx.NodeModel.FindOneServer(l.ctx, req.Id)
if err != nil {
l.Errorf("[UpdateServer] FindOneServer Error: %v", err.Error())
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find server error: %v", err.Error())
}
data.Name = req.Name
data.Country = req.Country
data.City = req.City
data.Ratio = req.Ratio
// only update address when it's different
if req.Address != data.Address {
// query server ip location
result, err := ip.GetRegionByIp(req.Address)
if err != nil {
l.Errorf("[UpdateServer] GetRegionByIp Error: %v", err.Error())
} else {
data.City = result.City
data.Country = result.Country
}
// update address
data.Address = req.Address
}
protocols := make([]node.Protocol, 0)
for _, item := range req.Protocols {
if item.Type == "" {
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.InvalidParams, "protocols type is empty"), "protocols type is empty")
}
var protocol node.Protocol
tool.DeepCopy(&protocol, item)
// VLESS Reality Key Generation
if protocol.Type == "vless" {
if protocol.Security == "reality" {
if protocol.RealityPublicKey == "" {
public, private, err := tool.Curve25519Genkey(false, "")
if err != nil {
l.Errorf("[CreateServer] Generate Reality Key Error: %v", err.Error())
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "generate reality key error: %v", err)
}
protocol.RealityPublicKey = public
protocol.RealityPrivateKey = private
protocol.RealityShortId = tool.GenerateShortID(private)
}
if protocol.RealityServerAddr == "" {
protocol.RealityServerAddr = protocol.SNI
}
if protocol.RealityServerPort == 0 {
protocol.RealityServerPort = 443
}
}
}
// ShadowSocks 2022 Key Generation
if protocol.Type == "shadowsocks" {
if strings.Contains(protocol.Cipher, "2022") {
var length int
switch protocol.Cipher {
case "2022-blake3-aes-128-gcm":
length = 16
default:
length = 32
}
if len(protocol.ServerKey) != length {
protocol.ServerKey = tool.GenerateCipher(protocol.ServerKey, length)
}
}
}
protocols = append(protocols, protocol)
}
err = data.MarshalProtocols(protocols)
if err != nil {
l.Errorf("[UpdateServer] Marshal Protocols Error: %v", err.Error())
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.InvalidParams, "protocols marshal error"), "protocols marshal error: %v", err)
}
err = l.svcCtx.NodeModel.UpdateServer(l.ctx, data)
if err != nil {
l.Errorf("[UpdateServer] UpdateServer Error: %v", err.Error())
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update server error: %v", err.Error())
}
return nil
}
@@ -1,4 +1,4 @@
package server
package server_bak
import (
"context"
@@ -1,4 +1,4 @@
package server
package server_bak
import (
"context"
@@ -1,4 +1,4 @@
package server
package server_bak
import (
"context"
@@ -0,0 +1,129 @@
package server_bak
import (
"context"
"encoding/json"
"strings"
"time"
"github.com/hibiken/asynq"
"github.com/perfect-panel/server/internal/model/server"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/tool"
"github.com/perfect-panel/server/pkg/xerr"
queue "github.com/perfect-panel/server/queue/types"
"github.com/pkg/errors"
)
type CreateNodeLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCreateNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateNodeLogic {
return &CreateNodeLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CreateNodeLogic) CreateNode(req *types.CreateNodeRequest) error {
config, err := json.Marshal(req.Config)
if err != nil {
return err
}
var serverInfo server.Server
tool.DeepCopy(&serverInfo, req)
serverInfo.Config = string(config)
nodeRelay, err := json.Marshal(req.RelayNode)
if err != nil {
l.Errorw("[UpdateNode] Marshal RelayNode Error: ", logger.Field("error", err.Error()))
return err
}
if len(req.Tags) > 0 {
serverInfo.Tags = strings.Join(req.Tags, ",")
}
serverInfo.LastReportedAt = time.UnixMicro(1218124800)
serverInfo.City = req.City
serverInfo.Country = req.Country
serverInfo.RelayNode = string(nodeRelay)
if req.Protocol == "vless" {
var cfg types.Vless
if err = json.Unmarshal(config, &cfg); err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
}
if cfg.Security == "reality" && cfg.SecurityConfig.RealityPublicKey == "" {
public, private, err := tool.Curve25519Genkey(false, "")
if err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "generate curve25519 key error")
}
cfg.SecurityConfig.RealityPublicKey = public
cfg.SecurityConfig.RealityPrivateKey = private
cfg.SecurityConfig.RealityShortId = tool.GenerateShortID(private)
}
if cfg.SecurityConfig.RealityServerAddr == "" {
cfg.SecurityConfig.RealityServerAddr = cfg.SecurityConfig.SNI
}
if cfg.SecurityConfig.RealityServerPort == 0 {
cfg.SecurityConfig.RealityServerPort = 443
}
config, _ = json.Marshal(cfg)
serverInfo.Config = string(config)
} else if req.Protocol == "shadowsocks" {
var cfg types.Shadowsocks
if err = json.Unmarshal(config, &cfg); err != nil {
l.Errorf("[CreateNode] Unmarshal Shadowsocks Config Error: %v", err.Error())
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
}
if strings.Contains(cfg.Method, "2022") {
var length int
switch cfg.Method {
case "2022-blake3-aes-128-gcm":
length = 16
default:
length = 32
}
if len(cfg.ServerKey) != length {
cfg.ServerKey = tool.GenerateCipher(cfg.ServerKey, length)
}
}
config, _ = json.Marshal(cfg)
serverInfo.Config = string(config)
}
err = l.svcCtx.ServerModel.Insert(l.ctx, &serverInfo)
if err != nil {
l.Errorw("[CreateNode] Insert Database Error: ", logger.Field("error", err.Error()))
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "create server error: %v", err)
}
if req.City == "" || req.Country == "" {
// Marshal the task payload
payload, err := json.Marshal(queue.GetNodeCountry{
Protocol: serverInfo.Protocol,
ServerAddr: serverInfo.ServerAddr,
})
if err != nil {
l.Errorw("[GetNodeCountry]: Marshal Error", logger.Field("error", err.Error()))
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to marshal task payload")
}
// Create a queue task
task := asynq.NewTask(queue.ForthwithGetCountry, payload)
// Enqueue the task
taskInfo, err := l.svcCtx.Queue.Enqueue(task)
if err != nil {
l.Errorw("[GetNodeCountry]: Enqueue Error", logger.Field("error", err.Error()), logger.Field("payload", string(payload)))
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to enqueue task")
}
l.Infow("[GetNodeCountry]: Enqueue Success", logger.Field("taskID", taskInfo.ID), logger.Field("payload", string(payload)))
}
return nil
}
@@ -1,4 +1,4 @@
package server
package server_bak
import (
"context"
@@ -1,4 +1,4 @@
package server
package server_bak
import (
"context"
@@ -0,0 +1,59 @@
package server_bak
import (
"context"
"github.com/perfect-panel/server/pkg/tool"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
"gorm.io/gorm"
)
type DeleteNodeLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteNodeLogic {
return &DeleteNodeLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DeleteNodeLogic) DeleteNode(req *types.DeleteNodeRequest) error {
err := l.svcCtx.DB.Transaction(func(tx *gorm.DB) error {
// Delete server
err := l.svcCtx.ServerModel.Delete(l.ctx, req.Id, tx)
if err != nil {
return err
}
// Delete server to subscribe
subs, err := l.svcCtx.SubscribeModel.QuerySubscribeIdsByServerIdAndServerGroupId(l.ctx, req.Id, 0)
if err != nil {
l.Logger.Errorf("[DeleteNode] QuerySubscribeIdsByServerIdAndServerGroupId error: %v", err.Error())
return err
}
for _, sub := range subs {
servers := tool.StringToInt64Slice(sub.Server)
newServers := tool.RemoveElementBySlice(servers, req.Id)
sub.Server = tool.Int64SliceToString(newServers)
if err = l.svcCtx.SubscribeModel.Update(l.ctx, sub, tx); err != nil {
l.Logger.Errorf("[DeleteNode] UpdateSubscribe error: %v", err.Error())
return err
}
}
return nil
})
if err != nil {
l.Errorw("[DeleteNode] Delete Database Error: ", logger.Field("error", err.Error()))
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseDeletedError), "delete server error: %v", err)
}
return nil
}
@@ -1,4 +1,4 @@
package server
package server_bak
import (
"context"
@@ -1,4 +1,4 @@
package server
package server_bak
import (
"context"
@@ -1,4 +1,4 @@
package server
package server_bak
import (
"context"
@@ -1,4 +1,4 @@
package server
package server_bak
import (
"context"
@@ -1,4 +1,4 @@
package server
package server_bak
import (
"context"
@@ -1,4 +1,4 @@
package server
package server_bak
import (
"context"
@@ -1,4 +1,4 @@
package server
package server_bak
import (
"context"
@@ -1,4 +1,4 @@
package server
package server_bak
import (
"context"
@@ -0,0 +1,139 @@
package server_bak
import (
"context"
"encoding/json"
"strings"
"github.com/hibiken/asynq"
"github.com/perfect-panel/server/pkg/device"
queue "github.com/perfect-panel/server/queue/types"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/tool"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type UpdateNodeLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUpdateNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateNodeLogic {
return &UpdateNodeLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UpdateNodeLogic) UpdateNode(req *types.UpdateNodeRequest) error {
// Check server exist
nodeInfo, err := l.svcCtx.ServerModel.FindOne(l.ctx, req.Id)
if err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find server error: %v", err)
}
tool.DeepCopy(nodeInfo, req, tool.CopyWithIgnoreEmpty(false))
config, err := json.Marshal(req.Config)
if err != nil {
return err
}
nodeInfo.Config = string(config)
nodeRelay, err := json.Marshal(req.RelayNode)
if err != nil {
l.Errorw("[UpdateNode] Marshal RelayNode Error: ", logger.Field("error", err.Error()))
return err
}
// 处理Tags字段
switch {
case len(req.Tags) > 0:
// 有Tags,进行连接
nodeInfo.Tags = strings.Join(req.Tags, ",")
default:
// 空数组,清空Tags
nodeInfo.Tags = ""
}
nodeInfo.City = req.City
nodeInfo.Country = req.Country
nodeInfo.RelayNode = string(nodeRelay)
if req.Protocol == "vless" {
var cfg types.Vless
if err := json.Unmarshal(config, &cfg); err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
}
if cfg.Security == "reality" && cfg.SecurityConfig.RealityPublicKey == "" {
public, private, err := tool.Curve25519Genkey(false, "")
if err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "generate curve25519 key error")
}
cfg.SecurityConfig.RealityPublicKey = public
cfg.SecurityConfig.RealityPrivateKey = private
cfg.SecurityConfig.RealityShortId = tool.GenerateShortID(private)
}
if cfg.SecurityConfig.RealityServerAddr == "" {
cfg.SecurityConfig.RealityServerAddr = cfg.SecurityConfig.SNI
}
if cfg.SecurityConfig.RealityServerPort == 0 {
cfg.SecurityConfig.RealityServerPort = 443
}
config, _ = json.Marshal(cfg)
nodeInfo.Config = string(config)
} else if req.Protocol == "shadowsocks" {
var cfg types.Shadowsocks
if err = json.Unmarshal(config, &cfg); err != nil {
l.Errorf("[CreateNode] Unmarshal Shadowsocks Config Error: %v", err.Error())
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
}
if strings.Contains(cfg.Method, "2022") {
var length int
switch cfg.Method {
case "2022-blake3-aes-128-gcm":
length = 16
default:
length = 32
}
if len(cfg.ServerKey) != length {
cfg.ServerKey = tool.GenerateCipher(cfg.ServerKey, length)
}
}
config, _ = json.Marshal(cfg)
nodeInfo.Config = string(config)
}
err = l.svcCtx.ServerModel.Update(l.ctx, nodeInfo)
if err != nil {
l.Errorw("[UpdateNode] Update Database Error: ", logger.Field("error", err.Error()))
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "create server error: %v", err)
}
if req.City == "" || req.Country == "" {
// Marshal the task payload
payload, err := json.Marshal(queue.GetNodeCountry{
Protocol: nodeInfo.Protocol,
ServerAddr: nodeInfo.ServerAddr,
})
if err != nil {
l.Errorw("[GetNodeCountry]: Marshal Error", logger.Field("error", err.Error()))
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to marshal task payload")
}
// Create a queue task
task := asynq.NewTask(queue.ForthwithGetCountry, payload)
// Enqueue the task
taskInfo, err := l.svcCtx.Queue.Enqueue(task)
if err != nil {
l.Errorw("[GetNodeCountry]: Enqueue Error", logger.Field("error", err.Error()), logger.Field("payload", string(payload)))
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to enqueue task")
}
l.Infow("[GetNodeCountry]: Enqueue Success", logger.Field("taskID", taskInfo.ID), logger.Field("payload", string(payload)))
}
l.svcCtx.DeviceManager.Broadcast(device.SubscribeUpdate)
return nil
}
@@ -1,4 +1,4 @@
package server
package server_bak
import (
"context"
@@ -65,7 +65,7 @@ func (l *OAuthLoginGetTokenLogic) OAuthLoginGetToken(req *types.OAuthLoginGetTok
)
defer func() {
l.recordLoginStatus(loginStatus, userInfo, ip, userAgent, requestID)
l.recordLoginStatus(loginStatus, userInfo, ip, userAgent, requestID, req.Method)
}()
userInfo, err = l.handleOAuthProvider(req, requestID)
@@ -487,10 +487,11 @@ func (l *OAuthLoginGetTokenLogic) createAuthMethod(db *gorm.DB, userID int64, au
return nil
}
func (l *OAuthLoginGetTokenLogic) recordLoginStatus(loginStatus bool, userInfo *user.User, ip, userAgent, requestID string) {
func (l *OAuthLoginGetTokenLogic) recordLoginStatus(loginStatus bool, userInfo *user.User, ip, userAgent, requestID, authType string) {
if userInfo != nil && userInfo.Id != 0 {
loginLog := log.Login{
Method: authType,
LoginIP: ip,
UserAgent: userAgent,
Success: loginStatus,
@@ -45,6 +45,7 @@ func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordRequest) (res
defer func() {
if userInfo.Id != 0 && loginStatus {
loginLog := log.Login{
Method: "email",
LoginIP: req.IP,
UserAgent: req.UserAgent,
Success: loginStatus,
@@ -53,6 +53,7 @@ func (l *TelephoneLoginLogic) TelephoneLogin(req *types.TelephoneLoginRequest, r
defer func(svcCtx *svc.ServiceContext) {
if userInfo.Id != 0 {
loginLog := log.Login{
Method: "mobile",
LoginIP: ip,
UserAgent: r.UserAgent(),
Success: loginStatus,
@@ -104,6 +104,7 @@ func (l *TelephoneResetPasswordLogic) TelephoneResetPassword(req *types.Telephon
defer func() {
if token != "" && userInfo.Id != 0 {
loginLog := log.Login{
Method: "mobile",
LoginIP: req.IP,
UserAgent: req.UserAgent,
Success: token != "",
@@ -159,6 +159,7 @@ func (l *TelephoneUserRegisterLogic) TelephoneUserRegister(req *types.TelephoneR
defer func() {
if token != "" && userInfo.Id != 0 {
loginLog := log.Login{
Method: "mobile",
LoginIP: req.IP,
UserAgent: req.UserAgent,
Success: token != "",
+1
View File
@@ -43,6 +43,7 @@ func (l *UserLoginLogic) UserLogin(req *types.UserLoginRequest) (resp *types.Log
defer func(svcCtx *svc.ServiceContext) {
if userInfo.Id != 0 {
loginLog := log.Login{
Method: "email",
LoginIP: req.IP,
UserAgent: req.UserAgent,
Success: loginStatus,
+1
View File
@@ -147,6 +147,7 @@ func (l *UserRegisterLogic) UserRegister(req *types.UserRegisterRequest) (resp *
defer func() {
if token != "" && userInfo.Id != 0 {
loginLog := log.Login{
Method: "email",
LoginIP: req.IP,
UserAgent: req.UserAgent,
Success: loginStatus,
@@ -20,7 +20,7 @@ type GetSubscribeLogLogic struct {
svcCtx *svc.ServiceContext
}
// Get Subscribe Log
// NewGetSubscribeLogLogic Get Subscribe Log
func NewGetSubscribeLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSubscribeLogLogic {
return &GetSubscribeLogLogic{
Logger: logger.WithContext(ctx),
@@ -39,7 +39,7 @@ func (l *GetSubscribeLogLogic) GetSubscribeLog(req *types.GetSubscribeLogRequest
Page: req.Page,
Size: req.Size,
Type: log.TypeSubscribe.Uint8(),
ObjectID: u.Id,
ObjectID: u.Id, // filter by current user id
})
if err != nil {
l.Errorw("[GetUserSubscribeLogs] Get User Subscribe Logs Error:", logger.Field("err", err.Error()))
@@ -56,7 +56,7 @@ func (l *GetSubscribeLogLogic) GetSubscribeLog(req *types.GetSubscribeLogRequest
list = append(list, types.UserSubscribeLog{
Id: item.Id,
UserId: item.ObjectID,
UserSubscribeId: content.SubscribeId,
UserSubscribeId: content.UserSubscribeId,
Token: content.Token,
IP: content.ClientIP,
UserAgent: content.UserAgent,
@@ -20,7 +20,7 @@ type QueryUserBalanceLogLogic struct {
svcCtx *svc.ServiceContext
}
// Query User Balance Log
// NewQueryUserBalanceLogLogic Query User Balance Log
func NewQueryUserBalanceLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryUserBalanceLogLogic {
return &QueryUserBalanceLogLogic{
Logger: logger.WithContext(ctx),
@@ -51,21 +51,20 @@ func (l *QueryUserBalanceLogLogic) QueryUserBalanceLog() (resp *types.QueryUserB
Total: total,
}
list := make([]types.UserBalanceLog, 0)
list := make([]types.BalanceLog, 0)
for _, datum := range data {
var content log.Balance
if err = content.Unmarshal([]byte(datum.Content)); err != nil {
l.Errorf("[QueryUserBalanceLog] unmarshal balance log content failed: %v", err.Error())
continue
}
list = append(list, types.UserBalanceLog{
Id: datum.Id,
list = append(list, types.BalanceLog{
UserId: datum.ObjectID,
Amount: content.Amount,
Type: content.Type,
OrderId: content.OrderId,
Balance: content.Balance,
CreatedAt: datum.CreatedAt.UnixMilli(),
Timestamp: content.Timestamp,
})
}
@@ -54,10 +54,10 @@ func (l *QueryUserCommissionLogLogic) QueryUserCommissionLog(req *types.QueryUse
continue
}
list = append(list, types.CommissionLog{
Id: datum.Id,
UserId: datum.ObjectID,
OrderNo: content.OrderNo,
Type: content.Type,
Amount: content.Amount,
OrderNo: content.OrderNo,
CreatedAt: content.CreatedAt,
})
}
+5 -4
View File
@@ -177,16 +177,17 @@ func (l *SubscribeLogic) logSubscribeActivity(subscribeStatus bool, userSub *use
}
subscribeLog := log.Subscribe{
Token: req.Token,
UserAgent: req.UA,
ClientIP: l.ctx.ClientIP(),
Token: req.Token,
UserAgent: req.UA,
ClientIP: l.ctx.ClientIP(),
UserSubscribeId: userSub.Id,
}
content, _ := subscribeLog.Marshal()
err := l.svc.LogModel.Insert(l.ctx.Request.Context(), &log.SystemLog{
Type: log.TypeSubscribe.Uint8(),
ObjectID: userSub.Id,
ObjectID: userSub.UserId, // log user id
Date: time.Now().Format(time.DateOnly),
Content: string(content),
})
-8
View File
@@ -39,14 +39,6 @@ const (
AllNodeUploadTrafficCacheKey = "node:all_node_upload_traffic"
// YesterdayTotalTrafficRank 昨日节点总流量排行榜
YesterdayNodeTotalTrafficRank = "node:yesterday_total_traffic_rank"
// YesterdayUploadTrafficRank 昨日节点上传流量排行榜
YesterdayNodeUploadTrafficRank = "node:yesterday_upload_traffic_rank"
// YesterdayDownloadTrafficRank 昨日节点下载流量排行榜
YesterdayNodeDownloadTrafficRank = "node:yesterday_download_traffic_rank"
// YesterdayUserTotalTrafficRank 昨日用户总流量排行榜
YesterdayUserTotalTrafficRank = "node:yesterday_user_total_traffic_rank"
// YesterdayUserUploadTrafficRank 昨日用户上传流量排行榜
YesterdayUserUploadTrafficRank = "node:yesterday_user_upload_traffic_rank"
// YesterdayUserDownloadTrafficRank 昨日用户下载流量排行榜
YesterdayUserDownloadTrafficRank = "node:yesterday_user_download_traffic_rank"
)
+51 -51
View File
@@ -7,20 +7,44 @@ import (
type Type uint8
/*
Log Types:
1X Message Logs
2X Subscription Logs
3X User Logs
4X Traffic Ranking Logs
*/
const (
TypeEmailMessage Type = iota + 1 // Message log
TypeMobileMessage // Mobile message log
TypeSubscribe // Subscription log
TypeSubscribeTraffic // Subscription traffic log
TypeServerTraffic // Server traffic log
TypeLogin // Login log
TypeRegister // Registration log
TypeBalance // Balance log
TypeCommission // Commission log
TypeResetSubscribe // Reset subscription log
TypeGift // Gift log
TypeUserTrafficRank // Top 10 User traffic rank log
TypeServerTrafficRank // Top 10 Server traffic rank log
TypeEmailMessage Type = 10 // Message log
TypeMobileMessage Type = 11 // Mobile message log
TypeSubscribe Type = 20 // Subscription log
TypeSubscribeTraffic Type = 21 // Subscription traffic log
TypeServerTraffic Type = 22 // Server traffic log
TypeResetSubscribe Type = 23 // Reset subscription log
TypeLogin Type = 30 // Login log
TypeRegister Type = 31 // Registration log
TypeBalance Type = 32 // Balance log
TypeCommission Type = 33 // Commission log
TypeGift Type = 34 // Gift log
TypeUserTrafficRank Type = 40 // Top 10 User traffic rank log
TypeServerTrafficRank Type = 41 // Top 10 Server traffic rank log
)
const (
ResetSubscribeTypeAuto uint16 = 231 // Auto reset
ResetSubscribeTypeAdvance uint16 = 232 // Advance reset
ResetSubscribeTypePaid uint16 = 233 // Paid reset
BalanceTypeRecharge uint16 = 321 // Recharge
BalanceTypeWithdraw uint16 = 322 // Withdraw
BalanceTypePayment uint16 = 323 // Payment
BalanceTypeRefund uint16 = 324 // Refund
BalanceTypeReward uint16 = 325 // Reward
CommissionTypePurchase uint16 = 331 // Purchase
CommissionTypeRenewal uint16 = 332 // Renewal
CommissionTypeRefund uint16 = 333 // Gift
GiftTypeIncrease uint16 = 341 // Increase
GiftTypeReduce uint16 = 342 // Reduce
)
// Uint8 converts Type to uint8.
@@ -95,6 +119,7 @@ func (s *Traffic) Unmarshal(data []byte) error {
// Login represents a login log entry.
type Login struct {
Method string `json:"method"`
LoginIP string `json:"login_ip"`
UserAgent string `json:"user_agent"`
Success bool `json:"success"`
@@ -147,10 +172,10 @@ func (r *Register) Unmarshal(data []byte) error {
// Subscribe represents a subscription log entry.
type Subscribe struct {
Token string `json:"token"`
UserAgent string `json:"user_agent"`
ClientIP string `json:"client_ip"`
SubscribeId int64 `json:"subscribe_id"`
Token string `json:"token"`
UserAgent string `json:"user_agent"`
ClientIP string `json:"client_ip"`
UserSubscribeId int64 `json:"user_subscribe_id"`
}
// Marshal implements the json.Marshaler interface for Subscribe.
@@ -170,15 +195,10 @@ func (s *Subscribe) Unmarshal(data []byte) error {
return json.Unmarshal(data, aux)
}
const (
ResetSubscribeTypeAuto uint8 = 1
ResetSubscribeTypeAdvance uint8 = 2
ResetSubscribeTypePaid uint8 = 3
)
// ResetSubscribe represents a reset subscription log entry.
type ResetSubscribe struct {
Type uint8 `json:"type"`
Type uint16 `json:"type"`
UserId int64 `json:"user_id"`
OrderNo string `json:"order_no,omitempty"`
ResetAt int64 `json:"reset_at"`
}
@@ -200,22 +220,13 @@ func (r *ResetSubscribe) Unmarshal(data []byte) error {
return json.Unmarshal(data, aux)
}
const (
BalanceTypeRecharge uint8 = 1 // Recharge
BalanceTypeWithdraw uint8 = 2 // Withdraw
BalanceTypePayment uint8 = 3 // Payment
BalanceTypeRefund uint8 = 4 // Refund
BalanceTypeReward uint8 = 5 // Reward
)
// Balance represents a balance log entry.
type Balance struct {
Id int64 `json:"id"`
Type uint8 `json:"type"`
Amount int64 `json:"amount"`
OrderId int64 `json:"order_id,omitempty"`
Balance int64 `json:"balance"`
Timestamp int64 `json:"timestamp"`
Type uint16 `json:"type"`
Amount int64 `json:"amount"`
OrderId int64 `json:"order_id,omitempty"`
Balance int64 `json:"balance"`
Timestamp int64 `json:"timestamp"`
}
// Marshal implements the json.Marshaler interface for Balance.
@@ -235,15 +246,9 @@ func (b *Balance) Unmarshal(data []byte) error {
return json.Unmarshal(data, aux)
}
const (
CommissionTypePurchase uint8 = 1 // Purchase
CommissionTypeRenewal uint8 = 2 // Renewal
CommissionTypeRefund uint8 = 3 // Gift
)
// Commission represents a commission log entry.
type Commission struct {
Type uint8 `json:"type"`
Type uint16 `json:"type"`
Amount int64 `json:"amount"`
OrderNo string `json:"order_no"`
CreatedAt int64 `json:"created_at"`
@@ -266,14 +271,9 @@ func (c *Commission) Unmarshal(data []byte) error {
return json.Unmarshal(data, aux)
}
const (
GiftTypeIncrease uint8 = 1 // Increase
GiftTypeReduce uint8 = 2 // Reduce
)
// Gift represents a gift log entry.
type Gift struct {
Type uint8 `json:"type"`
Type uint16 `json:"type"`
OrderNo string `json:"order_no"`
SubscribeId int64 `json:"subscribe_id"`
Amount int64 `json:"amount"`
+6
View File
@@ -16,6 +16,7 @@ type FilterParams struct {
Page int
Size int
Type uint8
Data string
Search string
ObjectID int64
}
@@ -43,6 +44,11 @@ func (m *customSystemLogModel) FilterSystemLog(ctx context.Context, filter *Filt
if filter.Type != 0 {
tx = tx.Where("`type` = ?", filter.Type)
}
if filter.Data != "" {
tx = tx.Where("`data` = ?", filter.Data)
}
if filter.ObjectID != 0 {
tx = tx.Where("`object_id` = ?", filter.ObjectID)
}
+127
View File
@@ -0,0 +1,127 @@
package node
import (
"context"
"gorm.io/gorm"
)
var _ Model = (*customServerModel)(nil)
//goland:noinspection GoNameStartsWithPackageName
type (
Model interface {
serverModel
NodeModel
customServerLogicModel
}
serverModel interface {
InsertServer(ctx context.Context, data *Server, tx ...*gorm.DB) error
FindOneServer(ctx context.Context, id int64) (*Server, error)
UpdateServer(ctx context.Context, data *Server, tx ...*gorm.DB) error
DeleteServer(ctx context.Context, id int64, tx ...*gorm.DB) error
Transaction(ctx context.Context, fn func(db *gorm.DB) error) error
}
NodeModel interface {
InsertNode(ctx context.Context, data *Node, tx ...*gorm.DB) error
FindOneNode(ctx context.Context, id int64) (*Node, error)
UpdateNode(ctx context.Context, data *Node, tx ...*gorm.DB) error
DeleteNode(ctx context.Context, id int64, tx ...*gorm.DB) error
}
customServerModel struct {
*defaultServerModel
}
defaultServerModel struct {
*gorm.DB
}
)
func newServerModel(db *gorm.DB) *defaultServerModel {
return &defaultServerModel{
DB: db,
}
}
// NewModel returns a model for the database table.
func NewModel(conn *gorm.DB) Model {
return &customServerModel{
defaultServerModel: newServerModel(conn),
}
}
func (m *defaultServerModel) InsertServer(ctx context.Context, data *Server, tx ...*gorm.DB) error {
db := m.DB
if len(tx) > 0 {
db = tx[0]
}
return db.WithContext(ctx).Create(data).Error
}
func (m *defaultServerModel) FindOneServer(ctx context.Context, id int64) (*Server, error) {
var server Server
err := m.WithContext(ctx).Model(&Server{}).Where("id = ?", id).First(&server).Error
return &server, err
}
func (m *defaultServerModel) UpdateServer(ctx context.Context, data *Server, tx ...*gorm.DB) error {
_, err := m.FindOneServer(ctx, data.Id)
if err != nil {
return err
}
db := m.DB
if len(tx) > 0 {
db = tx[0]
}
return db.WithContext(ctx).Save(data).Error
}
func (m *defaultServerModel) DeleteServer(ctx context.Context, id int64, tx ...*gorm.DB) error {
db := m.DB
if len(tx) > 0 {
db = tx[0]
}
return db.WithContext(ctx).Where("`id` = ?", id).Delete(&Server{}).Error
}
func (m *defaultServerModel) InsertNode(ctx context.Context, data *Node, tx ...*gorm.DB) error {
db := m.DB
if len(tx) > 0 {
db = tx[0]
}
return db.WithContext(ctx).Create(data).Error
}
func (m *defaultServerModel) FindOneNode(ctx context.Context, id int64) (*Node, error) {
var node Node
err := m.WithContext(ctx).Model(&Node{}).Where("id = ?", id).First(&node).Error
return &node, err
}
func (m *defaultServerModel) UpdateNode(ctx context.Context, data *Node, tx ...*gorm.DB) error {
_, err := m.FindOneNode(ctx, data.Id)
if err != nil {
return err
}
db := m.DB
if len(tx) > 0 {
db = tx[0]
}
return db.WithContext(ctx).Save(data).Error
}
func (m *defaultServerModel) DeleteNode(ctx context.Context, id int64, tx ...*gorm.DB) error {
db := m.DB
if len(tx) > 0 {
db = tx[0]
}
return db.WithContext(ctx).Where("`id` = ?", id).Delete(&Node{}).Error
}
func (m *defaultServerModel) Transaction(ctx context.Context, fn func(db *gorm.DB) error) error {
return m.WithContext(ctx).Transaction(fn)
}
+53
View File
@@ -0,0 +1,53 @@
package node
import "context"
type customServerLogicModel interface {
FilterServerList(ctx context.Context, params *FilterParams) (int64, []*Server, error)
FilterNodeList(ctx context.Context, params *FilterParams) (int64, []*Node, error)
}
// FilterParams Filter Server Params
type FilterParams struct {
Page int
Size int
Search string
}
// FilterServerList Filter Server List
func (m *customServerModel) FilterServerList(ctx context.Context, params *FilterParams) (int64, []*Server, error) {
var servers []*Server
var total int64
query := m.WithContext(ctx).Model(&Server{})
if params == nil {
params = &FilterParams{
Page: 1,
Size: 10,
}
}
if params.Search != "" {
s := "%" + params.Search + "%"
query = query.Where("`name` LIKE ? OR `address` LIKE ?", s, s)
}
err := query.Count(&total).Limit(params.Size).Offset((params.Page - 1) * params.Size).Find(&servers).Error
return total, servers, err
}
// FilterNodeList Filter Node List
func (m *customServerModel) FilterNodeList(ctx context.Context, params *FilterParams) (int64, []*Node, error) {
var nodes []*Node
var total int64
query := m.WithContext(ctx).Model(&Node{})
if params == nil {
params = &FilterParams{
Page: 1,
Size: 10,
}
}
if params.Search != "" {
s := "%" + params.Search + "%"
query = query.Where("`name` LIKE ? OR `address` LIKE ? OR `tags` LIKE ? OR `port` LIKE ? ", s, s, s, s)
}
err := query.Count(&total).Limit(params.Size).Offset((params.Page - 1) * params.Size).Find(&nodes).Error
return total, nodes, err
}
+20
View File
@@ -0,0 +1,20 @@
package node
import "time"
type Node struct {
Id int64 `gorm:"primary_key"`
Name string `gorm:"type:varchar(100);not null;default:'';comment:Node Name"`
Tags string `gorm:"type:varchar(255);not null;default:'';comment:Tags"`
Port uint16 `gorm:"not null;default:0;comment:Connect Port"`
Address string `gorm:"type:varchar(255);not null;default:'';comment:Connect Address"`
ServerId int64 `gorm:"not null;default:0;comment:Server ID"`
Protocol string `gorm:"type:varchar(100);not null;default:'';comment:Protocol"`
Enabled *bool `gorm:"type:boolean;not null;default:true;comment:Enabled"`
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
UpdatedAt time.Time `gorm:"comment:Update Time"`
}
func (Node) TableName() string {
return "nodes"
}
+108
View File
@@ -0,0 +1,108 @@
package node
import (
"encoding/json"
"time"
"github.com/pkg/errors"
)
type Server struct {
Id int64 `gorm:"primary_key"`
Name string `gorm:"type:varchar(100);not null;default:'';comment:Server Name"`
Country string `gorm:"type:varchar(128);not null;default:'';comment:Country"`
City string `gorm:"type:varchar(128);not null;default:'';comment:City"`
Ratio float32 `gorm:"type:DECIMAL(4,2);not null;default:0;comment:Traffic Ratio"`
Address string `gorm:"type:varchar(100);not null;default:'';comment:Server Address"`
Sort int `gorm:"type:int;not null;default:0;comment:Sort"`
Protocols string `gorm:"type:text;default:null;comment:Protocol"`
LastReportedAt time.Time `gorm:"comment:Last Reported Time"`
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
UpdatedAt time.Time `gorm:"comment:Update Time"`
}
func (*Server) TableName() string {
return "servers"
}
// MarshalProtocols Marshal server protocols to json
func (m *Server) MarshalProtocols(list []Protocol) error {
var validate = make(map[string]bool)
for _, protocol := range list {
if protocol.Type == "" {
return errors.New("protocol type is required")
}
if _, exists := validate[protocol.Type]; exists {
return errors.New("duplicate protocol type: " + protocol.Type)
}
validate[protocol.Type] = true
}
data, err := json.Marshal(list)
if err != nil {
return err
}
m.Protocols = string(data)
return nil
}
// UnmarshalProtocols Unmarshal server protocols from json
func (m *Server) UnmarshalProtocols() ([]Protocol, error) {
var list []Protocol
if m.Protocols == "" {
return list, nil
}
err := json.Unmarshal([]byte(m.Protocols), &list)
if err != nil {
return nil, err
}
return list, nil
}
type Protocol struct {
Type string `json:"type"`
Port uint16 `json:"port"`
Security string `json:"security,omitempty"`
SNI string `json:"sni,omitempty"`
AllowInsecure bool `json:"allow_insecure,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
RealityServerAddr string `json:"reality_server_addr,omitempty"`
RealityServerPort int `json:"reality_server_port,omitempty"`
RealityPrivateKey string `json:"reality_private_key,omitempty"`
RealityPublicKey string `json:"reality_public_key,omitempty"`
RealityShortId string `json:"reality_short_id,omitempty"`
Transport string `json:"transport,omitempty"`
Host string `json:"host,omitempty"`
Path string `json:"path,omitempty"`
ServiceName string `json:"service_name,omitempty"`
Cipher string `json:"cipher,omitempty"`
ServerKey string `json:"server_key,omitempty"`
Flow string `json:"flow,omitempty"`
HopPorts string `json:"hop_ports,omitempty"`
HopInterval int `json:"hop_interval,omitempty"`
ObfsPassword string `json:"obfs_password,omitempty"`
DisableSNI bool `json:"disable_sni,omitempty"`
ReduceRtt bool `json:"reduce_rtt,omitempty"`
UDPRelayMode string `json:"udp_relay_mode,omitempty"`
CongestionController string `json:"congestion_controller,omitempty"`
}
// Marshal protocol to json
func (m *Protocol) Marshal() ([]byte, error) {
type Alias Protocol
return json.Marshal(&struct {
*Alias
}{
Alias: (*Alias)(m),
})
}
// Unmarshal json to protocol
func (m *Protocol) Unmarshal(data []byte) error {
type Alias Protocol
aux := &struct {
*Alias
}{
Alias: (*Alias)(m),
}
return json.Unmarshal(data, &aux)
}
+3
View File
@@ -4,6 +4,7 @@ import (
"context"
"github.com/perfect-panel/server/internal/model/client"
"github.com/perfect-panel/server/internal/model/node"
"github.com/perfect-panel/server/pkg/device"
"github.com/perfect-panel/server/internal/model/ads"
@@ -43,6 +44,7 @@ type ServiceContext struct {
AuthModel auth.Model
AdsModel ads.Model
LogModel log.Model
NodeModel node.Model
UserModel user.Model
OrderModel order.Model
ClientModel client.Model
@@ -93,6 +95,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
AuthLimiter: authLimiter,
AdsModel: ads.NewModel(db, rds),
LogModel: log.NewModel(db),
NodeModel: node.NewModel(db),
AuthModel: auth.NewModel(db, rds),
UserModel: user.NewModel(db, rds),
OrderModel: order.NewModel(db, rds),
+324 -148
View File
@@ -128,6 +128,15 @@ type AuthMethodConfig struct {
Enabled bool `json:"enabled"`
}
type BalanceLog struct {
Type uint16 `json:"type"`
UserId int64 `json:"user_id"`
Amount int64 `json:"amount"`
OrderId int64 `json:"order_id,omitempty"`
Balance int64 `json:"balance"`
Timestamp int64 `json:"timestamp"`
}
type BatchDeleteCouponRequest struct {
Ids []int64 `json:"ids" validate:"required"`
}
@@ -136,14 +145,6 @@ type BatchDeleteDocumentRequest struct {
Ids []int64 `json:"ids" validate:"required"`
}
type BatchDeleteNodeGroupRequest struct {
Ids []int64 `json:"ids" validate:"required"`
}
type BatchDeleteNodeRequest struct {
Ids []int64 `json:"ids" validate:"required"`
}
type BatchDeleteSubscribeGroupRequest struct {
Ids []int64 `json:"ids" validate:"required"`
}
@@ -230,10 +231,10 @@ type CloseOrderRequest struct {
}
type CommissionLog struct {
Id int64 `json:"id"`
Type uint16 `json:"type"`
UserId int64 `json:"user_id"`
OrderNo string `json:"order_no"`
Amount int64 `json:"amount"`
OrderNo string `json:"order_no"`
CreatedAt int64 `json:"created_at"`
}
@@ -303,26 +304,14 @@ type CreateDocumentRequest struct {
Show *bool `json:"show"`
}
type CreateNodeGroupRequest struct {
Name string `json:"name" validate:"required"`
Description string `json:"description"`
}
type CreateNodeRequest struct {
Name string `json:"name" validate:"required"`
Tags []string `json:"tags"`
Country string `json:"country"`
City string `json:"city"`
ServerAddr string `json:"server_addr" validate:"required"`
RelayMode string `json:"relay_mode"`
RelayNode []NodeRelay `json:"relay_node"`
SpeedLimit int `json:"speed_limit"`
TrafficRatio float32 `json:"traffic_ratio"`
GroupId int64 `json:"group_id"`
Protocol string `json:"protocol" validate:"required"`
Config interface{} `json:"config" validate:"required"`
Enable *bool `json:"enable"`
Sort int64 `json:"sort"`
Name string `json:"name"`
Tags []string `json:"tags,omitempty"`
Port uint16 `json:"port"`
Address string `json:"address"`
ServerId int64 `json:"server_id"`
Protocol string `json:"protocol"`
Enabled *bool `json:"enabled"`
}
type CreateOrderRequest struct {
@@ -355,14 +344,14 @@ type CreatePaymentMethodRequest struct {
Enable *bool `json:"enable" validate:"required"`
}
type CreateRuleGroupRequest struct {
Name string `json:"name" validate:"required"`
Icon string `json:"icon"`
Type string `json:"type"`
Tags []string `json:"tags"`
Rules string `json:"rules"`
Default bool `json:"default"`
Enable bool `json:"enable"`
type CreateServerRequest struct {
Name string `json:"name"`
Country string `json:"country,omitempty"`
City string `json:"city,omitempty"`
Ratio float32 `json:"ratio"`
Address string `json:"address"`
Sort int `json:"sort,omitempty"`
Protocols []Protocol `json:"protocols"`
}
type CreateSubscribeApplicationRequest struct {
@@ -479,20 +468,16 @@ type DeleteDocumentRequest struct {
Id int64 `json:"id" validate:"required"`
}
type DeleteNodeGroupRequest struct {
Id int64 `json:"id" validate:"required"`
}
type DeleteNodeRequest struct {
Id int64 `json:"id" validate:"required"`
Id int64 `json:"id"`
}
type DeletePaymentMethodRequest struct {
Id int64 `json:"id" validate:"required"`
}
type DeleteRuleGroupRequest struct {
Id int64 `json:"id" validate:"required"`
type DeleteServerRequest struct {
Id int64 `json:"id"`
}
type DeleteSubscribeApplicationRequest struct {
@@ -559,6 +544,136 @@ type EmailAuthticateConfig struct {
DomainSuffixList string `json:"domain_suffix_list"`
}
type FilterBalanceLogRequest struct {
FilterLogParams
UserId int64 `form:"user_id,optional"`
}
type FilterBalanceLogResponse struct {
Total int64 `json:"total"`
List []BalanceLog `json:"list"`
}
type FilterCommissionLogRequest struct {
FilterLogParams
UserId int64 `form:"user_id,optional"`
}
type FilterCommissionLogResponse struct {
Total int64 `json:"total"`
List []CommissionLog `json:"list"`
}
type FilterEmailLogResponse struct {
Total int64 `json:"total"`
List []MessageLog `json:"list"`
}
type FilterGiftLogRequest struct {
FilterLogParams
UserId int64 `form:"user_id,optional"`
}
type FilterGiftLogResponse struct {
Total int64 `json:"total"`
List []GiftLog `json:"list"`
}
type FilterLogParams struct {
Page int `form:"page"`
Size int `form:"size"`
Date string `form:"date,optional"`
Search string `form:"search,optional"`
}
type FilterLoginLogRequest struct {
FilterLogParams
UserId int64 `form:"user_id,optional"`
}
type FilterLoginLogResponse struct {
Total int64 `json:"total"`
List []LoginLog `json:"list"`
}
type FilterMobileLogResponse struct {
Total int64 `json:"total"`
List []MessageLog `json:"list"`
}
type FilterNodeListRequest struct {
Page int `form:"page"`
Size int `form:"size"`
Search string `form:"search,omitempty"`
}
type FilterNodeListResponse struct {
Total int64 `json:"total"`
List []Node `json:"list"`
}
type FilterRegisterLogRequest struct {
FilterLogParams
UserId int64 `form:"user_id,optional"`
}
type FilterRegisterLogResponse struct {
Total int64 `json:"total"`
List []RegisterLog `json:"list"`
}
type FilterResetSubscribeLogRequest struct {
FilterLogParams
UserSubscribeId int64 `form:"user_subscribe_id,optional"`
}
type FilterResetSubscribeLogResponse struct {
Total int64 `json:"total"`
List []ResetSubscribeLog `json:"list"`
}
type FilterServerListRequest struct {
Page int `form:"page"`
Size int `form:"size"`
Search string `form:"search,omitempty"`
}
type FilterServerListResponse struct {
Total int64 `json:"total"`
List []Server `json:"list"`
}
type FilterServerTrafficLogRequest struct {
FilterLogParams
ServerId int64 `form:"server_id,optional"`
}
type FilterServerTrafficLogResponse struct {
Total int64 `json:"total"`
List []ServerTrafficLog `json:"list"`
}
type FilterSubscribeLogRequest struct {
FilterLogParams
UserId int64 `form:"user_id,optional"`
}
type FilterSubscribeLogResponse struct {
Total int64 `json:"total"`
List []SubscribeLog `json:"list"`
}
type FilterSubscribeTrafficRequest struct {
FilterLogParams
UserId int64 `form:"user_id,optional"`
UserSubscribeId int64 `form:"user_subscribe_id,optional"`
}
type FilterSubscribeTrafficResponse struct {
Total int64 `json:"total"`
List []UserSubscribeTrafficLog `json:"list"`
}
type Follow struct {
Id int64 `json:"id"`
TicketId int64 `json:"ticket_id"`
@@ -712,36 +827,10 @@ type GetMessageLogListResponse struct {
List []MessageLog `json:"list"`
}
type GetNodeDetailRequest struct {
Id int64 `form:"id" validate:"required"`
}
type GetNodeGroupListResponse struct {
Total int64 `json:"total"`
List []ServerGroup `json:"list"`
}
type GetNodeMultiplierResponse struct {
Periods []TimePeriod `json:"periods"`
}
type GetNodeServerListRequest struct {
Page int `form:"page" validate:"required"`
Size int `form:"size" validate:"required"`
Tags string `form:"tags,omitempty"`
GroupId int64 `form:"group_id,omitempty"`
Search string `form:"search,omitempty"`
}
type GetNodeServerListResponse struct {
Total int64 `json:"total"`
List []Server `json:"list"`
}
type GetNodeTagListResponse struct {
Tags []string `json:"tags"`
}
type GetOAuthMethodsResponse struct {
Methods []UserAuthMethod `json:"methods"`
}
@@ -783,11 +872,6 @@ type GetPreSendEmailCountResponse struct {
Count int64 `json:"count"`
}
type GetRuleGroupResponse struct {
Total int64 `json:"total"`
List []ServerRuleGroup `json:"list"`
}
type GetServerConfigRequest struct {
ServerCommon
}
@@ -798,6 +882,14 @@ type GetServerConfigResponse struct {
Config interface{} `json:"config"`
}
type GetServerProtocolsRequest struct {
Id int64 `form:"id"`
}
type GetServerProtocolsResponse struct {
Protocols []Protocol `json:"protocols"`
}
type GetServerUserListRequest struct {
ServerCommon
}
@@ -997,6 +1089,17 @@ type GetUserTicketListResponse struct {
List []Ticket `json:"list"`
}
type GiftLog struct {
Type uint16 `json:"type"`
UserId int64 `json:"user_id"`
OrderNo string `json:"order_no"`
SubscribeId int64 `json:"subscribe_id"`
Amount int64 `json:"amount"`
Balance int64 `json:"balance"`
Remark string `json:"remark,omitempty"`
CreatedAt int64 `json:"created_at"`
}
type GoogleLoginCallbackRequest struct {
Code string `form:"code"`
State string `form:"state"`
@@ -1024,6 +1127,15 @@ type LogResponse struct {
List interface{} `json:"list"`
}
type LoginLog struct {
UserId int64 `json:"user_id"`
Method string `json:"method"`
LoginIP string `json:"login_ip"`
UserAgent string `json:"user_agent"`
Success bool `json:"success"`
LoginTime int64 `json:"login_time"`
}
type LoginResponse struct {
Token string `json:"token"`
}
@@ -1045,6 +1157,19 @@ type MobileAuthenticateConfig struct {
Whitelist []string `json:"whitelist"`
}
type Node struct {
Id int64 `json:"id"`
Name string `json:"name"`
Tags []string `json:"tags"`
Port uint16 `json:"port"`
Address string `json:"address"`
ServerId int64 `json:"server_id"`
Protocol string `json:"protocol"`
Enabled *bool `json:"enabled"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
type NodeConfig struct {
NodeSecret string `json:"node_secret"`
NodePullInterval int64 `json:"node_pull_interval"`
@@ -1057,18 +1182,6 @@ type NodeRelay struct {
Prefix string `json:"prefix"`
}
type NodeSortRequest struct {
Sort []SortItem `json:"sort"`
}
type NodeStatus struct {
Online interface{} `json:"online"`
Cpu float64 `json:"cpu"`
Mem float64 `json:"mem"`
Disk float64 `json:"disk"`
UpdatedAt int64 `json:"updated_at"`
}
type OAthLoginRequest struct {
Method string `json:"method" validate:"required"` // google, facebook, apple, telegram, github etc.
Redirect string `json:"redirect"`
@@ -1263,6 +1376,34 @@ type PrivacyPolicyConfig struct {
PrivacyPolicy string `json:"privacy_policy"`
}
type Protocol struct {
Type string `json:"type"`
Port uint16 `json:"port"`
Security string `json:"security,omitempty"`
SNI string `json:"sni,omitempty"`
AllowInsecure bool `json:"allow_insecure,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
RealityServerAddr string `json:"reality_server_addr,omitempty"`
RealityServerPort int `json:"reality_server_port,omitempty"`
RealityPrivateKey string `json:"reality_private_key,omitempty"`
RealityPublicKey string `json:"reality_public_key,omitempty"`
RealityShortId string `json:"reality_short_id,omitempty"`
Transport string `json:"transport,omitempty"`
Host string `json:"host,omitempty"`
Path string `json:"path,omitempty"`
ServiceName string `json:"service_name,omitempty"`
Cipher string `json:"cipher,omitempty"`
ServerKey string `json:"server_key,omitempty"`
Flow string `json:"flow,omitempty"`
HopPorts string `json:"hop_ports,omitempty"`
HopInterval int `json:"hop_interval,omitempty"`
ObfsPassword string `json:"obfs_password,omitempty"`
DisableSNI bool `json:"disable_sni,omitempty"`
ReduceRtt bool `json:"reduce_rtt,omitempty"`
UDPRelayMode string `json:"udp_relay_mode,omitempty"`
CongestionController string `json:"congestion_controller,omitempty"`
}
type PubilcRegisterConfig struct {
StopRegister bool `json:"stop_register"`
EnableIpRegisterLimit bool `json:"enable_ip_register_limit"`
@@ -1368,8 +1509,8 @@ type QueryUserAffiliateListResponse struct {
}
type QueryUserBalanceLogListResponse struct {
List []UserBalanceLog `json:"list"`
Total int64 `json:"total"`
List []BalanceLog `json:"list"`
Total int64 `json:"total"`
}
type QueryUserCommissionLogListRequest struct {
@@ -1407,6 +1548,15 @@ type RegisterConfig struct {
IpRegisterLimitDuration int64 `json:"ip_register_limit_duration"`
}
type RegisterLog struct {
UserId int64 `json:"user_id"`
AuthMethod string `json:"auth_method"`
Identifier string `json:"identifier"`
RegisterIP string `json:"register_ip"`
UserAgent string `json:"user_agent"`
RegisterTime int64 `json:"register_time"`
}
type RenewalOrderRequest struct {
UserSubscribeID int64 `json:"user_subscribe_id"`
Quantity int64 `json:"quantity"`
@@ -1427,9 +1577,17 @@ type ResetPasswordRequest struct {
CfToken string `json:"cf_token,optional"`
}
type ResetSubscribeLog struct {
Type uint16 `json:"type"`
UserId int64 `json:"user_id"`
UserSubscribeId int64 `json:"user_subscribe_id"`
OrderNo string `json:"order_no,omitempty"`
ResetAt int64 `json:"reset_at"`
}
type ResetSubscribeTrafficLog struct {
Id int64 `json:"id"`
Type uint8 `json:"type"`
Type uint16 `json:"type"`
UserSubscribeId int64 `json:"user_subscribe_id"`
OrderNo string `json:"order_no,omitempty"`
ResetAt int64 `json:"reset_at"`
@@ -1482,24 +1640,18 @@ type SendSmsCodeRequest struct {
}
type Server struct {
Id int64 `json:"id"`
Tags []string `json:"tags"`
Country string `json:"country"`
City string `json:"city"`
Name string `json:"name"`
ServerAddr string `json:"server_addr"`
RelayMode string `json:"relay_mode"`
RelayNode []NodeRelay `json:"relay_node"`
SpeedLimit int `json:"speed_limit"`
TrafficRatio float32 `json:"traffic_ratio"`
GroupId int64 `json:"group_id"`
Protocol string `json:"protocol"`
Config interface{} `json:"config"`
Enable *bool `json:"enable"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
Status *NodeStatus `json:"status"`
Sort int64 `json:"sort"`
Id int64 `json:"id"`
Name string `json:"name"`
Country string `json:"country"`
City string `json:"city"`
Ratio float32 `json:"ratio"`
Address string `json:"address"`
Sort int `json:"sort"`
Protocols []Protocol `json:"protocols"`
LastReportedAt int64 `json:"last_reported_at"`
Status ServerStatus `json:"status"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
type ServerBasic struct {
@@ -1521,6 +1673,15 @@ type ServerGroup struct {
UpdatedAt int64 `json:"updated_at"`
}
type ServerOnlineUser struct {
IP []string `json:"ip"`
UserId int64 `json:"user_id"`
Subscribe string `json:"subscribe"`
SubscribeId int64 `json:"subscribe_id"`
Traffic int64 `json:"traffic"`
ExpiredAt int64 `json:"expired_at"`
}
type ServerPushStatusRequest struct {
ServerCommon
Cpu float64 `json:"cpu"`
@@ -1547,6 +1708,13 @@ type ServerRuleGroup struct {
UpdatedAt int64 `json:"updated_at"`
}
type ServerStatus struct {
Online []ServerOnlineUser `json:"online"`
Cpu float64 `json:"cpu"`
Mem float64 `json:"mem"`
Disk float64 `json:"disk"`
}
type ServerTotalDataResponse struct {
OnlineUserIPs int64 `json:"online_user_ips"`
OnlineServers int64 `json:"online_servers"`
@@ -1569,6 +1737,14 @@ type ServerTrafficData struct {
Download int64 `json:"download"`
}
type ServerTrafficLog struct {
ServerId int64 `json:"server_id"` // Server ID
Upload int64 `json:"upload"` // Upload traffic in bytes
Download int64 `json:"download"` // Download traffic in bytes
Total int64 `json:"total"` // Total traffic in bytes (Upload + Download)
Date string `json:"date"` // Date in YYYY-MM-DD format
}
type ServerUser struct {
Id int64 `json:"id"`
UUID string `json:"uuid"`
@@ -1701,6 +1877,15 @@ type SubscribeItem struct {
Sold int64 `json:"sold"`
}
type SubscribeLog struct {
UserId int64 `json:"user_id"`
Token string `json:"token"`
UserAgent string `json:"user_agent"`
ClientIP string `json:"client_ip"`
UserSubscribeId int64 `json:"user_subscribe_id"`
SubscribedAt int64 `json:"subscribed_at"`
}
type SubscribeSortRequest struct {
Sort []SortItem `json:"sort"`
}
@@ -1786,6 +1971,11 @@ type TimePeriod struct {
Multiplier float32 `json:"multiplier"`
}
type ToggleNodeStatusRequest struct {
Id int64 `json:"id"`
Enable *bool `json:"enable"`
}
type TosConfig struct {
TosContent string `json:"tos_content"`
}
@@ -1906,28 +2096,15 @@ type UpdateDocumentRequest struct {
Show *bool `json:"show"`
}
type UpdateNodeGroupRequest struct {
Id int64 `json:"id" validate:"required"`
Name string `json:"name" validate:"required"`
Description string `json:"description"`
}
type UpdateNodeRequest struct {
Id int64 `json:"id" validate:"required"`
Tags []string `json:"tags"`
Country string `json:"country"`
City string `json:"city"`
Name string `json:"name" validate:"required"`
ServerAddr string `json:"server_addr" validate:"required"`
RelayMode string `json:"relay_mode"`
RelayNode []NodeRelay `json:"relay_node"`
SpeedLimit int `json:"speed_limit"`
TrafficRatio float32 `json:"traffic_ratio"`
GroupId int64 `json:"group_id"`
Protocol string `json:"protocol" validate:"required"`
Config interface{} `json:"config" validate:"required"`
Enable *bool `json:"enable"`
Sort int64 `json:"sort"`
Id int64 `json:"id"`
Name string `json:"name"`
Tags []string `json:"tags,omitempty"`
Port uint16 `json:"port"`
Address string `json:"address"`
ServerId int64 `json:"server_id"`
Protocol string `json:"protocol"`
Enabled *bool `json:"enabled"`
}
type UpdateOrderStatusRequest struct {
@@ -1951,15 +2128,15 @@ type UpdatePaymentMethodRequest struct {
Enable *bool `json:"enable" validate:"required"`
}
type UpdateRuleGroupRequest struct {
Id int64 `json:"id" validate:"required"`
Icon string `json:"icon"`
Type string `json:"type"`
Name string `json:"name" validate:"required"`
Tags []string `json:"tags"`
Rules string `json:"rules"`
Default bool `json:"default"`
Enable bool `json:"enable"`
type UpdateServerRequest struct {
Id int64 `json:"id"`
Name string `json:"name"`
Country string `json:"country,omitempty"`
City string `json:"city,omitempty"`
Ratio float32 `json:"ratio"`
Address string `json:"address"`
Sort int `json:"sort,omitempty"`
Protocols []Protocol `json:"protocols"`
}
type UpdateSubscribeApplicationRequest struct {
@@ -2100,16 +2277,6 @@ type UserAuthMethod struct {
Verified bool `json:"verified"`
}
type UserBalanceLog struct {
Id int64 `json:"id"`
UserId int64 `json:"user_id"`
Amount int64 `json:"amount"`
Type uint8 `json:"type"`
OrderId int64 `json:"order_id"`
Balance int64 `json:"balance"`
CreatedAt int64 `json:"created_at"`
}
type UserDevice struct {
Id int64 `json:"id"`
Ip string `json:"ip"`
@@ -2210,6 +2377,15 @@ type UserSubscribeLog struct {
CreatedAt int64 `json:"created_at"`
}
type UserSubscribeTrafficLog struct {
SubscribeId int64 `json:"subscribe_id"` // Subscribe ID
UserId int64 `json:"user_id"` // User ID
Upload int64 `json:"upload"` // Upload traffic in bytes
Download int64 `json:"download"` // Download traffic in bytes
Total int64 `json:"total"` // Total traffic in bytes (Upload + Download)
Date string `json:"date"` // Date in YYYY-MM-DD format
}
type UserTraffic struct {
SID int64 `json:"uid"`
Upload int64 `json:"upload"`