Initial commit (code only without large binaries)

This commit is contained in:
robin
2026-02-15 18:58:44 +08:00
commit 35df75498f
9442 changed files with 1495866 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package plan
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/types"
)
type DeleteAction struct {
actionutils.ParentAction
}
func (this *DeleteAction) RunPost(params struct {
PlanId int64
}) {
defer this.CreateLogInfo(codes.NSPlan_LogDeleteNSPlan, params.PlanId)
// 检查是否有用户在使用
countResp, err := this.RPC().NSUserPlanRPC().CountNSUserPlans(this.AdminContext(), &pb.CountNSUserPlansRequest{
NsPlanId: params.PlanId,
})
if err != nil {
this.ErrorPage(err)
return
}
if countResp.Count > 0 {
this.Fail("有" + types.String(countResp.Count) + "个用户正在使用此套餐,请转移用户套餐后再删除")
return
}
_, err = this.RPC().NSPlanRPC().DeleteNSPlan(this.AdminContext(), &pb.DeleteNSPlanRequest{NsPlanId: params.PlanId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,134 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package plan
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type UpdatePopupAction struct {
actionutils.ParentAction
}
func (this *UpdatePopupAction) Init() {
this.Nav("", "", "")
}
func (this *UpdatePopupAction) RunGet(params struct {
PlanId int64
}) {
planResp, err := this.RPC().NSPlanRPC().FindNSPlan(this.AdminContext(), &pb.FindNSPlanRequest{NsPlanId: params.PlanId})
if err != nil {
this.ErrorPage(err)
return
}
var plan = planResp.NsPlan
if plan == nil {
this.NotFound("NSPlan", params.PlanId)
return
}
var config = dnsconfigs.DefaultNSPlanConfig()
if len(plan.ConfigJSON) > 0 {
err = json.Unmarshal(plan.ConfigJSON, config)
if err != nil {
this.ErrorPage(err)
return
}
}
this.Data["plan"] = maps.Map{
"id": plan.Id,
"name": plan.Name,
"isOn": plan.IsOn,
"monthlyPrice": plan.MonthlyPrice,
"yearlyPrice": plan.YearlyPrice,
"config": config,
}
this.Show()
}
func (this *UpdatePopupAction) RunPost(params struct {
PlanId int64
Name string
MonthlyPrice float32
YearlyPrice float32
SupportCountryRoutes bool
SupportChinaProvinceRoutes bool
SupportISPRoutes bool
SupportAgentRoutes bool
SupportPublicRoutes bool
SupportHealthCheck bool
MinTTL int32
MaxDomains int32
MaxRecordsPerDomain int32
MaxLoadBalanceRecordsPerRecord int32
MaxCustomRoutes int32
IsOn bool
Must *actions.Must
CSRF *actionutils.CSRF
}) {
defer this.CreateLogInfo(codes.NSPlan_LogUpdateNSPlan, params.PlanId)
params.Must.
Field("name", params.Name).
Require("请输入套餐名称").
Field("monthlyPrice", params.MonthlyPrice).
Gt(0, "请输入按月价格").
Field("yearlyPrice", params.YearlyPrice).
Gt(0, "请输入按年价格")
var config = dnsconfigs.DefaultNSPlanConfig()
config.SupportCountryRoutes = params.SupportCountryRoutes
config.SupportChinaProvinceRoutes = params.SupportChinaProvinceRoutes
config.SupportISPRoutes = params.SupportISPRoutes
config.SupportAgentRoutes = params.SupportAgentRoutes
config.SupportPublicRoutes = params.SupportPublicRoutes
config.SupportHealthCheck = params.SupportHealthCheck
config.MinTTL = params.MinTTL
config.MaxDomains = params.MaxDomains
config.MaxRecordsPerDomain = params.MaxRecordsPerDomain
config.MaxLoadBalanceRecordsPerRecord = params.MaxLoadBalanceRecordsPerRecord
config.MaxCustomRoutes = params.MaxCustomRoutes
err := config.Init()
if err != nil {
this.Fail("配置校验失败:" + err.Error())
}
configJSON, err := json.Marshal(config)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().NSPlanRPC().UpdateNSPlan(this.AdminContext(), &pb.UpdateNSPlanRequest{
NsPlanId: params.PlanId,
Name: params.Name,
MonthlyPrice: params.MonthlyPrice,
YearlyPrice: params.YearlyPrice,
ConfigJSON: configJSON,
IsOn: params.IsOn,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}