mirror of
https://github.com/VaalaCat/frp-panel.git
synced 2025-09-26 19:31:18 +08:00
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package server
|
|
|
|
import (
|
|
"github.com/VaalaCat/frp-panel/common"
|
|
"github.com/VaalaCat/frp-panel/models"
|
|
"github.com/VaalaCat/frp-panel/pb"
|
|
"github.com/VaalaCat/frp-panel/services/app"
|
|
"github.com/VaalaCat/frp-panel/services/dao"
|
|
"github.com/VaalaCat/frp-panel/utils"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func InitServerHandler(c *app.Context, req *pb.InitServerRequest) (*pb.InitServerResponse, error) {
|
|
var (
|
|
userServerID = req.GetServerId()
|
|
serverIP = req.GetServerIp()
|
|
userInfo = common.GetUserInfo(c)
|
|
)
|
|
|
|
if !userInfo.Valid() {
|
|
return &pb.InitServerResponse{
|
|
Status: &pb.Status{Code: pb.RespCode_RESP_CODE_INVALID, Message: "invalid user"},
|
|
}, nil
|
|
}
|
|
|
|
if len(userServerID) == 0 || len(serverIP) == 0 || !utils.IsClientIDPermited(userServerID) {
|
|
return &pb.InitServerResponse{
|
|
Status: &pb.Status{Code: pb.RespCode_RESP_CODE_INVALID, Message: "request invalid"},
|
|
}, nil
|
|
}
|
|
|
|
globalServerID := app.GlobalClientID(userInfo.GetUserName(), "s", userServerID)
|
|
|
|
if err := dao.NewQuery(c).CreateServer(userInfo,
|
|
&models.ServerEntity{
|
|
ServerID: globalServerID,
|
|
TenantID: userInfo.GetTenantID(),
|
|
UserID: userInfo.GetUserID(),
|
|
ConnectSecret: uuid.New().String(),
|
|
ServerIP: serverIP,
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &pb.InitServerResponse{
|
|
Status: &pb.Status{Code: pb.RespCode_RESP_CODE_SUCCESS, Message: "ok"},
|
|
ServerId: &globalServerID,
|
|
}, nil
|
|
}
|