Compare commits
3 Commits
c8fd4cf9ca
...
v1.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
| bf8f001a30 | |||
| eac793becb | |||
| 7bdbb7ddff |
30
Dockerfile
30
Dockerfile
@@ -1,35 +1,31 @@
|
||||
# 第一阶段:构建
|
||||
FROM golang:1.24.0 AS builder
|
||||
|
||||
ENV GOPROXY=https://goproxy.cn,direct
|
||||
|
||||
FROM golang:1.25.3 AS builder
|
||||
WORKDIR /build
|
||||
|
||||
# 复制Go模块文件
|
||||
ENV GOPROXY=https://goproxy.cn,direct
|
||||
ENV CGO_ENABLED=0
|
||||
ENV GOOS=linux
|
||||
ENV GOARCH=amd64
|
||||
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# 复制源代码
|
||||
COPY . .
|
||||
|
||||
# 编译
|
||||
RUN GOOS=linux GOARCH=amd64 go build -ldflags '-w -s' -o bin/platform_linux_amd64 cmd/main/main.go
|
||||
RUN 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
|
||||
|
||||
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
|
||||
|
||||
# 设置可执行权限
|
||||
RUN chmod +x /app/platform
|
||||
|
||||
# 声明暴露端口
|
||||
EXPOSE 8080
|
||||
|
||||
# 启动平台服务
|
||||
CMD ["/app/platform"]
|
||||
CMD ["/app/platform"]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: lanhu
|
||||
name: lanhu-platform
|
||||
|
||||
services:
|
||||
postgres:
|
||||
|
||||
12
scripts/sql/fill.sql
Normal file
12
scripts/sql/fill.sql
Normal 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
|
||||
@@ -1059,16 +1059,3 @@ alter table coupon
|
||||
add constraint fk_coupon_user_id foreign key (user_id) references "user" (id) on delete cascade;
|
||||
|
||||
-- endregion
|
||||
|
||||
-- ====================
|
||||
-- region 填充数据
|
||||
-- ====================
|
||||
|
||||
insert into client (
|
||||
client_id, client_secret, redirect_uri, spec, name, type
|
||||
)
|
||||
values (
|
||||
'web', '$2a$10$Ss12mXQgpYyo1CKIZ3URouDm.Lc2KcYJzsvEK2PTIXlv6fHQht45a', '', 3, 'web', 1
|
||||
);
|
||||
|
||||
-- endregion
|
||||
|
||||
@@ -3,7 +3,9 @@ package handlers
|
||||
import (
|
||||
"net/netip"
|
||||
"platform/pkg/env"
|
||||
"platform/web/auth"
|
||||
"platform/web/core"
|
||||
"platform/web/globals"
|
||||
s "platform/web/services"
|
||||
"time"
|
||||
|
||||
@@ -23,20 +25,40 @@ func DebugRegisterProxyBaiYin(c *fiber.Ctx) error {
|
||||
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 报告上线
|
||||
|
||||
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) {
|
||||
return c.JSON(map[string]any{
|
||||
"error": "接口暂不可用",
|
||||
@@ -140,12 +162,19 @@ func ProxyReportOnline(c *fiber.Ctx) (err error) {
|
||||
// })
|
||||
}
|
||||
|
||||
// region 报告下线
|
||||
|
||||
type ProxyReportOfflineReq struct {
|
||||
Id int32 `json:"id" validate:"required"`
|
||||
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"`
|
||||
}
|
||||
|
||||
// region 报告下线
|
||||
func ProxyReportOffline(c *fiber.Ctx) (err error) {
|
||||
return c.JSON(map[string]any{
|
||||
"error": "接口暂不可用",
|
||||
@@ -183,13 +212,11 @@ func ProxyReportOffline(c *fiber.Ctx) (err error) {
|
||||
// return nil
|
||||
}
|
||||
|
||||
// region 报告更新
|
||||
|
||||
type ProxyReportUpdateReq struct {
|
||||
Id int32 `json:"id" validate:"required"`
|
||||
Edges []*ProxyEdge `json:"edges" validate:"required"`
|
||||
type ProxyReportOfflineReq struct {
|
||||
Id int32 `json:"id" validate:"required"`
|
||||
}
|
||||
|
||||
// region 报告更新
|
||||
func ProxyReportUpdate(c *fiber.Ctx) (err error) {
|
||||
return c.JSON(map[string]any{
|
||||
"error": "接口暂不可用",
|
||||
@@ -348,6 +375,11 @@ func ProxyReportUpdate(c *fiber.Ctx) (err error) {
|
||||
// return nil
|
||||
}
|
||||
|
||||
type ProxyReportUpdateReq struct {
|
||||
Id int32 `json:"id" validate:"required"`
|
||||
Edges []*ProxyEdge `json:"edges" validate:"required"`
|
||||
}
|
||||
|
||||
type ProxyPermit struct {
|
||||
Id int32 `json:"id"`
|
||||
Expire time.Time `json:"expire"`
|
||||
|
||||
@@ -72,13 +72,14 @@ func ApplyRouters(app *fiber.App) {
|
||||
proxy.Post("/online", handlers.ProxyReportOnline)
|
||||
proxy.Post("/offline", handlers.ProxyReportOffline)
|
||||
proxy.Post("/update", handlers.ProxyReportUpdate)
|
||||
proxy.Post("/register", handlers.ProxyRegisterBaiYin)
|
||||
|
||||
// 节点
|
||||
edge := api.Group("/edge")
|
||||
edge.Post("/assign", handlers.AssignEdge)
|
||||
edge.Post("/all", handlers.AllEdgesAvailable)
|
||||
|
||||
// 其他系统接口
|
||||
// 前台
|
||||
inquiry := api.Group("/inquiry")
|
||||
inquiry.Post("/create", handlers.CreateInquiry)
|
||||
|
||||
|
||||
@@ -31,12 +31,12 @@ func (s *proxyService) AllProxies(proxyType m.ProxyType, channels bool) ([]*m.Pr
|
||||
}
|
||||
|
||||
// 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{
|
||||
Version: 0,
|
||||
Mac: Mac,
|
||||
Mac: Name,
|
||||
IP: orm.Inet{Addr: IP},
|
||||
Secret: u.P(fmt.Sprintf("%s:%s", username, password)),
|
||||
Type: m.ProxyTypeBaiYin,
|
||||
|
||||
Reference in New Issue
Block a user