转发服务注册后提供一个密钥用于安全通信

This commit is contained in:
2025-05-15 15:59:28 +08:00
parent f5396ce9d8
commit 9043dd779b

View File

@@ -1,6 +1,7 @@
package handlers package handlers
import ( import (
"crypto/rand"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"log/slog" "log/slog"
auth2 "platform/web/auth" auth2 "platform/web/auth"
@@ -21,6 +22,7 @@ type OnlineProxyReq struct {
type OnlineProxyResp struct { type OnlineProxyResp struct {
Id int32 `json:"id"` Id int32 `json:"id"`
Secret string `json:"secret"`
} }
func OnlineProxy(c *fiber.Ctx) (err error) { func OnlineProxy(c *fiber.Ctx) (err error) {
@@ -41,12 +43,14 @@ func OnlineProxy(c *fiber.Ctx) (err error) {
} }
// 创建代理 // 创建代理
ip := c.Context().RemoteIP() var ip = c.Context().RemoteIP()
var secret = rand.Text()
var proxy = &m.Proxy{ var proxy = &m.Proxy{
Name: req.Name, Name: req.Name,
Version: int32(req.Version), Version: int32(req.Version),
Host: ip.String(),
Type: int32(proxy2.TypeSelfHosted), Type: int32(proxy2.TypeSelfHosted),
Host: ip.String(),
Secret: secret,
Status: 1, Status: 1,
} }
err = q.Proxy. err = q.Proxy.
@@ -64,6 +68,7 @@ func OnlineProxy(c *fiber.Ctx) (err error) {
slog.Debug("注册转发服务", "ip", ip, "id", proxy.ID) slog.Debug("注册转发服务", "ip", ip, "id", proxy.ID)
return c.JSON(&OnlineProxyResp{ return c.JSON(&OnlineProxyResp{
Id: proxy.ID, Id: proxy.ID,
Secret: secret,
}) })
} }