This commit is contained in:
unknown
2026-02-04 20:27:13 +08:00
commit 3b042d1dad
9410 changed files with 1488147 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package accesslogs
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/iwind/TeaGo/actions"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
this.SecondMenu("accessLog")
}
func (this *IndexAction) RunGet(params struct{}) {
resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{
Code: systemconfigs.SettingCodeNSAccessLogSetting,
})
if err != nil {
this.ErrorPage(err)
return
}
var config = &dnsconfigs.NSAccessLogRef{}
if len(resp.ValueJSON) > 0 {
err = json.Unmarshal(resp.ValueJSON, config)
if err != nil {
this.ErrorPage(err)
return
}
} else {
config.IsOn = true
config.LogMissingDomains = true
}
this.Data["config"] = config
this.Show()
}
func (this *IndexAction) RunPost(params struct {
AccessLogJSON []byte
Must *actions.Must
CSRF *actionutils.CSRF
}) {
// 校验配置
var config = &dnsconfigs.NSAccessLogRef{}
err := json.Unmarshal(params.AccessLogJSON, config)
if err != nil {
this.Fail("配置解析失败:" + err.Error())
}
err = config.Init()
if err != nil {
this.Fail("配置校验失败:" + err.Error())
}
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
Code: systemconfigs.SettingCodeNSAccessLogSetting,
ValueJSON: params.AccessLogJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,26 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package accesslogs
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/settings/settingutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(plus.NewHelper(plus.ComponentCodeNS)).
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNS)).
Helper(new(settingutils.Helper)).
Data("teaMenu", "ns").
Data("teaSubMenu", "setting").
Prefix("/ns/settings/accesslogs").
GetPost("", new(IndexAction)).
EndAll()
})
}

View File

@@ -0,0 +1,17 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package settings
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
}
func (this *IndexAction) RunGet(params struct{}) {
this.RedirectURL("/ns/settings/user")
}

View File

@@ -0,0 +1,36 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package settingutils
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type Helper struct {
helpers.LangHelper
}
func (this *Helper) BeforeAction(actionPtr actions.ActionWrapper) (goNext bool) {
var action = actionPtr.Object()
secondMenuItem := action.Data.GetString("secondMenuItem")
action.Data["leftMenuItems"] = this.createSettingMenu(secondMenuItem, actionPtr)
return true
}
func (this *Helper) createSettingMenu(selectedItem string, actionPtr actions.ActionWrapper) (items []maps.Map) {
return []maps.Map{
{
"name": this.Lang(actionPtr, codes.NS_SettingUser),
"url": "/ns/settings/user",
"isActive": selectedItem == "user",
},
{
"name": this.Lang(actionPtr, codes.NS_SettingAccessLogs),
"url": "/ns/settings/accesslogs",
"isActive": selectedItem == "accessLog",
},
}
}

View File

@@ -0,0 +1,33 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package user
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type ClusterHostsAction struct {
actionutils.ParentAction
}
func (this *ClusterHostsAction) RunPost(params struct {
ClusterId int64
}) {
hostsResp, err := this.RPC().NSClusterRPC().FindNSClusterHosts(this.AdminContext(), &pb.FindNSClusterHostsRequest{
NsClusterId: params.ClusterId,
})
if err != nil {
this.ErrorPage(err)
return
}
var hosts = hostsResp.Hosts
if hosts == nil {
hosts = []string{}
}
this.Data["hosts"] = hosts
this.Success()
}

View File

@@ -0,0 +1,170 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package user
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/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/iwind/TeaGo/actions"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
this.SecondMenu("user")
}
func (this *IndexAction) RunGet(params struct{}) {
resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{
Code: systemconfigs.SettingCodeNSUserConfig,
})
if err != nil {
this.ErrorPage(err)
return
}
var config = dnsconfigs.NewNSUserConfig()
if len(resp.ValueJSON) > 0 {
err = json.Unmarshal(resp.ValueJSON, config)
if err != nil {
this.ErrorPage(err)
return
}
if config.DefaultPlanConfig == nil {
config.DefaultPlanConfig = dnsconfigs.DefaultNSUserPlanConfig()
}
}
if config.DomainValidation == nil {
config.DomainValidation = dnsconfigs.NewNSDomainValidationConfig()
}
// 当前集群主机地址
var clusterHosts = []string{}
if config.DefaultClusterId > 0 {
hostsResp, err := this.RPC().NSClusterRPC().FindNSClusterHosts(this.AdminContext(), &pb.FindNSClusterHostsRequest{
NsClusterId: config.DefaultClusterId,
})
if err != nil {
this.ErrorPage(err)
return
}
if len(hostsResp.Hosts) > 0 {
clusterHosts = hostsResp.Hosts
}
}
this.Data["clusterHosts"] = clusterHosts
this.Data["config"] = config
this.Show()
}
func (this *IndexAction) RunPost(params struct {
DefaultClusterId int64
DomainValidationIsOn bool
DomainValidationResolversJSON []byte
SupportCountryRoutes bool
SupportChinaProvinceRoutes bool
SupportISPRoutes bool
SupportAgentRoutes bool
SupportPublicRoutes bool
SupportHealthCheck bool
MinTTL int32
MaxDomains int32
MaxRecordsPerDomain int32
MaxLoadBalanceRecordsPerRecord int32
MaxCustomRoutes int32
Must *actions.Must
CSRF *actionutils.CSRF
}) {
defer this.CreateLogInfo(codes.NS_LogUpdateNSUserConfig)
if params.DefaultClusterId <= 0 {
this.Fail("选择默认部署集群")
}
resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{
Code: systemconfigs.SettingCodeNSUserConfig,
})
if err != nil {
this.ErrorPage(err)
return
}
var config = dnsconfigs.NewNSUserConfig()
if len(resp.ValueJSON) > 0 {
err = json.Unmarshal(resp.ValueJSON, config)
if err != nil {
this.ErrorPage(err)
return
}
}
// 默认集群
config.DefaultClusterId = params.DefaultClusterId
// 域名验证
if config.DomainValidation == nil {
config.DomainValidation = dnsconfigs.NewNSDomainValidationConfig()
}
config.DomainValidation.IsOn = params.DomainValidationIsOn
config.DomainValidation.Resolvers = []*dnsconfigs.DNSResolver{}
err = json.Unmarshal(params.DomainValidationResolversJSON, &config.DomainValidation.Resolvers)
if err != nil {
this.ErrorPage(err)
return
}
// 基础功能
var planConfig = dnsconfigs.DefaultNSPlanConfig()
planConfig.SupportCountryRoutes = params.SupportCountryRoutes
planConfig.SupportChinaProvinceRoutes = params.SupportChinaProvinceRoutes
planConfig.SupportISPRoutes = params.SupportISPRoutes
planConfig.SupportAgentRoutes = params.SupportAgentRoutes
planConfig.SupportPublicRoutes = params.SupportPublicRoutes
planConfig.SupportHealthCheck = params.SupportHealthCheck
planConfig.MinTTL = params.MinTTL
planConfig.MaxDomains = params.MaxDomains
planConfig.MaxRecordsPerDomain = params.MaxRecordsPerDomain
planConfig.MaxLoadBalanceRecordsPerRecord = params.MaxLoadBalanceRecordsPerRecord
planConfig.MaxCustomRoutes = params.MaxCustomRoutes
err = planConfig.Init()
if err != nil {
this.Fail("默认功能配置校验失败:" + err.Error())
}
config.DefaultPlanConfig = planConfig
// 保存
configJSON, err := json.Marshal(config)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
Code: systemconfigs.SettingCodeNSUserConfig,
ValueJSON: configJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,27 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package user
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/settings/settingutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(plus.NewHelper(plus.ComponentCodeNS)).
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNS)).
Helper(new(settingutils.Helper)).
Data("teaMenu", "ns").
Data("teaSubMenu", "setting").
Prefix("/ns/settings/user").
GetPost("", new(IndexAction)).
Post("/clusterHosts", new(ClusterHostsAction)).
EndAll()
})
}