feat(protocol): add server protocol configuration query and enhance protocol options
This commit is contained in:
@@ -842,4 +842,11 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
|
||||
// Get user list
|
||||
serverGroupRouter.GET("/user", server.GetServerUserListHandler(serverCtx))
|
||||
}
|
||||
|
||||
serverV2GroupRouter := router.Group("/v2/server")
|
||||
|
||||
{
|
||||
// Get Server Protocol Config
|
||||
serverV2GroupRouter.GET("/:server_id", server.QueryServerProtocolConfigHandler(serverCtx))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/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/result"
|
||||
)
|
||||
|
||||
// QueryServerProtocolConfigHandler Get Server Protocol Config
|
||||
func QueryServerProtocolConfigHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.QueryServerConfigRequest
|
||||
|
||||
serverID, err := strconv.ParseInt(c.Param("server_id"), 10, 64)
|
||||
if err != nil {
|
||||
logger.Debugf("[QueryServerProtocolConfigHandler] - strconv.ParseInt(server_id) error: %v, Param: %s", err, c.Param("server_id"))
|
||||
c.String(http.StatusBadRequest, "Invalid Params")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
req.ServerID = serverID
|
||||
|
||||
key := c.GetHeader("secret_key")
|
||||
if key == "" || key != svcCtx.Config.Node.NodeSecret {
|
||||
logger.Debugf("[QueryServerProtocolConfigHandler] - secret_key error: %s", key)
|
||||
c.String(http.StatusUnauthorized, "Unauthorized")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
l := server.NewQueryServerProtocolConfigLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryServerProtocolConfig(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,9 @@ import (
|
||||
"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 GetServerProtocolsLogic struct {
|
||||
@@ -24,7 +27,23 @@ func NewGetServerProtocolsLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
|
||||
func (l *GetServerProtocolsLogic) GetServerProtocols(req *types.GetServerProtocolsRequest) (resp *types.GetServerProtocolsResponse, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
// find server
|
||||
data, err := l.svcCtx.NodeModel.FindOneServer(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
l.Errorf("[GetServerProtocols] FindOneServer Error: %s", err.Error())
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "[GetServerProtocols] FindOneServer Error: %s", err.Error())
|
||||
}
|
||||
|
||||
return
|
||||
// handler protocols
|
||||
var protocols []types.Protocol
|
||||
dst, err := data.UnmarshalProtocols()
|
||||
if err != nil {
|
||||
l.Errorf("[FilterServerList] UnmarshalProtocols Error: %s", err.Error())
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "[FilterServerList] UnmarshalProtocols Error: %s", err.Error())
|
||||
}
|
||||
tool.DeepCopy(&protocols, dst)
|
||||
|
||||
return &types.GetServerProtocolsResponse{
|
||||
Protocols: protocols,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
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/tool"
|
||||
)
|
||||
|
||||
type QueryServerProtocolConfigLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// NewQueryServerProtocolConfigLogic Get Server Protocol Config
|
||||
func NewQueryServerProtocolConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryServerProtocolConfigLogic {
|
||||
return &QueryServerProtocolConfigLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *QueryServerProtocolConfigLogic) QueryServerProtocolConfig(req *types.QueryServerConfigRequest) (resp *types.QueryServerConfigResponse, err error) {
|
||||
// find server
|
||||
data, err := l.svcCtx.NodeModel.FindOneServer(l.ctx, req.ServerID)
|
||||
if err != nil {
|
||||
l.Errorf("[GetServerProtocols] FindOneServer Error: %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// handler protocols
|
||||
var protocols []types.Protocol
|
||||
dst, err := data.UnmarshalProtocols()
|
||||
if err != nil {
|
||||
l.Errorf("[FilterServerList] UnmarshalProtocols Error: %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
tool.DeepCopy(&protocols, dst)
|
||||
|
||||
return &types.QueryServerConfigResponse{
|
||||
Protocols: protocols,
|
||||
}, nil
|
||||
}
|
||||
@@ -126,6 +126,12 @@ type Protocol struct {
|
||||
ReduceRtt bool `json:"reduce_rtt,omitempty"`
|
||||
UDPRelayMode string `json:"udp_relay_mode,omitempty"`
|
||||
CongestionController string `json:"congestion_controller,omitempty"`
|
||||
Plugin string `json:"plugin,omitempty"` // obfs, v2ray-plugin, simple-obfs
|
||||
PluginOptions string `json:"plugin_options,omitempty"` // plugin options, eg: obfs=http;obfs-host=www.bing.com
|
||||
Multiplex string `json:"multiplex,omitempty"` // mux, eg: off/low/medium/high
|
||||
PaddingScheme string `json:"padding_scheme,omitempty"` // padding scheme
|
||||
UpMbps int `json:"up_mbps,omitempty"` // upload speed limit
|
||||
DownMbps int `json:"down_mbps,omitempty"` // download speed limit
|
||||
}
|
||||
|
||||
// Marshal protocol to json
|
||||
|
||||
@@ -1448,6 +1448,12 @@ type Protocol struct {
|
||||
ReduceRtt bool `json:"reduce_rtt,omitempty"`
|
||||
UDPRelayMode string `json:"udp_relay_mode,omitempty"`
|
||||
CongestionController string `json:"congestion_controller,omitempty"`
|
||||
Plugin string `json:"plugin,omitempty"` // obfs, v2ray-plugin, simple-obfs
|
||||
PluginOptions string `json:"plugin_options,omitempty"` // plugin options, eg: obfs=http;obfs-host=www.bing.com
|
||||
Multiplex string `json:"multiplex,omitempty"` // mux, eg: off/low/medium/high
|
||||
PaddingScheme string `json:"padding_scheme,omitempty"` // padding scheme
|
||||
UpMbps int `json:"up_mbps,omitempty"` // upload speed limit
|
||||
DownMbps int `json:"down_mbps,omitempty"` // download speed limit
|
||||
}
|
||||
|
||||
type PubilcRegisterConfig struct {
|
||||
@@ -1566,6 +1572,15 @@ type QueryQuotaTaskStatusResponse struct {
|
||||
Errors string `json:"errors"`
|
||||
}
|
||||
|
||||
type QueryServerConfigRequest struct {
|
||||
ServerID int64 `path:"server_id"`
|
||||
SecretKey string `header:"secret_key"`
|
||||
}
|
||||
|
||||
type QueryServerConfigResponse struct {
|
||||
Protocols []Protocol `json:"protocols"`
|
||||
}
|
||||
|
||||
type QuerySubscribeGroupListResponse struct {
|
||||
List []SubscribeGroup `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
|
||||
Reference in New Issue
Block a user