3 Commits

Author SHA1 Message Date
bf8f001a30 新增代理注册接口
Some checks failed
Docker / build (push) Has been cancelled
2025-12-22 17:31:31 +08:00
eac793becb 优化 sql 脚本,排除无关填充流程
Some checks failed
Docker / build (push) Has been cancelled
2025-12-20 18:47:21 +08:00
7bdbb7ddff 优化 Dockerfile
Some checks failed
Docker / build (push) Has been cancelled
2025-12-20 15:15:54 +08:00
7 changed files with 84 additions and 56 deletions

View File

@@ -1,35 +1,31 @@
# 第一阶段:构建 # 第一阶段:构建
FROM golang:1.24.0 AS builder FROM golang:1.25.3 AS builder
ENV GOPROXY=https://goproxy.cn,direct
WORKDIR /build WORKDIR /build
# 复制Go模块文件 ENV GOPROXY=https://goproxy.cn,direct
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
COPY go.mod go.sum ./ COPY go.mod go.sum ./
RUN go mod download RUN go mod download
# 复制源代码
COPY . . COPY . .
RUN go build -ldflags '-w -s' -o bin/platform_linux_amd64 cmd/main/main.go
# 编译
RUN GOOS=linux GOARCH=amd64 go build -ldflags '-w -s' -o bin/platform_linux_amd64 cmd/main/main.go
# 第二阶段:运行环境 # 第二阶段:运行环境
FROM ubuntu:24.04 AS runner FROM alpine:3.23 AS runner
WORKDIR /app WORKDIR /app
RUN apt-get update && apt-get install -y ca-certificates ENV TZ=Asia/Shanghai
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
RUN apk add --no-cache ca-certificates tzdata
# 从构建阶段复制编译好的二进制文件
COPY --from=builder /build/bin/platform_linux_amd64 /app/platform COPY --from=builder /build/bin/platform_linux_amd64 /app/platform
# 设置可执行权限
RUN chmod +x /app/platform RUN chmod +x /app/platform
# 声明暴露端口
EXPOSE 8080 EXPOSE 8080
# 启动平台服务 CMD ["/app/platform"]
CMD ["/app/platform"]

View File

@@ -1,4 +1,4 @@
name: lanhu name: lanhu-platform
services: services:
postgres: postgres:

12
scripts/sql/fill.sql Normal file
View File

@@ -0,0 +1,12 @@
-- ====================
-- region 填充数据
-- ====================
insert into client (
client_id, client_secret, redirect_uri, spec, name, type
)
values (
'web', '$2a$10$Ss12mXQgpYyo1CKIZ3URouDm.Lc2KcYJzsvEK2PTIXlv6fHQht45a', '', 3, 'web', 1
);
-- endregion

View File

@@ -1059,16 +1059,3 @@ alter table coupon
add constraint fk_coupon_user_id foreign key (user_id) references "user" (id) on delete cascade; add constraint fk_coupon_user_id foreign key (user_id) references "user" (id) on delete cascade;
-- endregion -- endregion
-- ====================
-- region 填充数据
-- ====================
insert into client (
client_id, client_secret, redirect_uri, spec, name, type
)
values (
'web', '$2a$10$Ss12mXQgpYyo1CKIZ3URouDm.Lc2KcYJzsvEK2PTIXlv6fHQht45a', '', 3, 'web', 1
);
-- endregion

View File

@@ -3,7 +3,9 @@ package handlers
import ( import (
"net/netip" "net/netip"
"platform/pkg/env" "platform/pkg/env"
"platform/web/auth"
"platform/web/core" "platform/web/core"
"platform/web/globals"
s "platform/web/services" s "platform/web/services"
"time" "time"
@@ -23,20 +25,40 @@ func DebugRegisterProxyBaiYin(c *fiber.Ctx) error {
return nil return nil
} }
// 注册白银代理网关
func ProxyRegisterBaiYin(c *fiber.Ctx) error {
_, err := auth.GetAuthCtx(c).PermitOfficialClient()
if err != nil {
return err
}
req := new(RegisterProxyBaiyinReq)
err = globals.Validator.ParseBody(c, req)
if err != nil {
return err
}
addr, err := netip.ParseAddr(req.IP)
if err != nil {
return core.NewServErr("IP地址格式错误", err)
}
err = s.Proxy.RegisterBaiyin(req.Name, addr, req.Username, req.Password)
if err != nil {
return core.NewServErr("注册失败", err)
}
return nil
}
type RegisterProxyBaiyinReq struct {
Name string `json:"name" validate:"required"`
IP string `json:"ip" validate:"required"`
Username string `json:"username" validate:"required"`
Password string `json:"password" validate:"required"`
}
// region 报告上线 // region 报告上线
type ProxyReportOnlineReq struct {
Name string `json:"name" validate:"required"`
Version int `json:"version" validate:"required"`
}
type ProxyReportOnlineResp struct {
Id int32 `json:"id"`
Secret string `json:"secret"`
Permits []*ProxyPermit `json:"permits"`
Edges []*ProxyEdge `json:"edges"`
}
func ProxyReportOnline(c *fiber.Ctx) (err error) { func ProxyReportOnline(c *fiber.Ctx) (err error) {
return c.JSON(map[string]any{ return c.JSON(map[string]any{
"error": "接口暂不可用", "error": "接口暂不可用",
@@ -140,12 +162,19 @@ func ProxyReportOnline(c *fiber.Ctx) (err error) {
// }) // })
} }
// region 报告下线 type ProxyReportOnlineReq struct {
Name string `json:"name" validate:"required"`
type ProxyReportOfflineReq struct { Version int `json:"version" validate:"required"`
Id int32 `json:"id" validate:"required"`
} }
type ProxyReportOnlineResp struct {
Id int32 `json:"id"`
Secret string `json:"secret"`
Permits []*ProxyPermit `json:"permits"`
Edges []*ProxyEdge `json:"edges"`
}
// region 报告下线
func ProxyReportOffline(c *fiber.Ctx) (err error) { func ProxyReportOffline(c *fiber.Ctx) (err error) {
return c.JSON(map[string]any{ return c.JSON(map[string]any{
"error": "接口暂不可用", "error": "接口暂不可用",
@@ -183,13 +212,11 @@ func ProxyReportOffline(c *fiber.Ctx) (err error) {
// return nil // return nil
} }
// region 报告更新 type ProxyReportOfflineReq struct {
Id int32 `json:"id" validate:"required"`
type ProxyReportUpdateReq struct {
Id int32 `json:"id" validate:"required"`
Edges []*ProxyEdge `json:"edges" validate:"required"`
} }
// region 报告更新
func ProxyReportUpdate(c *fiber.Ctx) (err error) { func ProxyReportUpdate(c *fiber.Ctx) (err error) {
return c.JSON(map[string]any{ return c.JSON(map[string]any{
"error": "接口暂不可用", "error": "接口暂不可用",
@@ -348,6 +375,11 @@ func ProxyReportUpdate(c *fiber.Ctx) (err error) {
// return nil // return nil
} }
type ProxyReportUpdateReq struct {
Id int32 `json:"id" validate:"required"`
Edges []*ProxyEdge `json:"edges" validate:"required"`
}
type ProxyPermit struct { type ProxyPermit struct {
Id int32 `json:"id"` Id int32 `json:"id"`
Expire time.Time `json:"expire"` Expire time.Time `json:"expire"`

View File

@@ -72,13 +72,14 @@ func ApplyRouters(app *fiber.App) {
proxy.Post("/online", handlers.ProxyReportOnline) proxy.Post("/online", handlers.ProxyReportOnline)
proxy.Post("/offline", handlers.ProxyReportOffline) proxy.Post("/offline", handlers.ProxyReportOffline)
proxy.Post("/update", handlers.ProxyReportUpdate) proxy.Post("/update", handlers.ProxyReportUpdate)
proxy.Post("/register", handlers.ProxyRegisterBaiYin)
// 节点 // 节点
edge := api.Group("/edge") edge := api.Group("/edge")
edge.Post("/assign", handlers.AssignEdge) edge.Post("/assign", handlers.AssignEdge)
edge.Post("/all", handlers.AllEdgesAvailable) edge.Post("/all", handlers.AllEdgesAvailable)
// 其他系统接口 // 前台
inquiry := api.Group("/inquiry") inquiry := api.Group("/inquiry")
inquiry.Post("/create", handlers.CreateInquiry) inquiry.Post("/create", handlers.CreateInquiry)

View File

@@ -31,12 +31,12 @@ func (s *proxyService) AllProxies(proxyType m.ProxyType, channels bool) ([]*m.Pr
} }
// RegisterBaiyin 注册新代理服务 // RegisterBaiyin 注册新代理服务
func (s *proxyService) RegisterBaiyin(Mac string, IP netip.Addr, username, password string) error { func (s *proxyService) RegisterBaiyin(Name string, IP netip.Addr, username, password string) error {
// 保存代理信息 // 保存代理信息
proxy := &m.Proxy{ proxy := &m.Proxy{
Version: 0, Version: 0,
Mac: Mac, Mac: Name,
IP: orm.Inet{Addr: IP}, IP: orm.Inet{Addr: IP},
Secret: u.P(fmt.Sprintf("%s:%s", username, password)), Secret: u.P(fmt.Sprintf("%s:%s", username, password)),
Type: m.ProxyTypeBaiYin, Type: m.ProxyTypeBaiYin,