部分中文转换为多语言代号

This commit is contained in:
GoEdgeLab
2023-06-28 19:07:42 +08:00
parent 0aae6a5beb
commit 4724f2ac96
26 changed files with 103 additions and 85 deletions

View File

@@ -317,7 +317,7 @@ func (this *CreateNodeAction) RunPost(params struct {
"id": grantResp.NodeGrant.Id,
"name": grantResp.NodeGrant.Name,
"method": grantResp.NodeGrant.Method,
"methodName": grantutils.FindGrantMethodName(grantResp.NodeGrant.Method),
"methodName": grantutils.FindGrantMethodName(grantResp.NodeGrant.Method, this.LangCode()),
"username": grantResp.NodeGrant.Username,
}
}

View File

@@ -219,7 +219,7 @@ func (this *DetailAction) RunGet(params struct {
"id": grantResp.NodeGrant.Id,
"name": grantResp.NodeGrant.Name,
"method": grantResp.NodeGrant.Method,
"methodName": grantutils.FindGrantMethodName(grantResp.NodeGrant.Method),
"methodName": grantutils.FindGrantMethodName(grantResp.NodeGrant.Method, this.LangCode()),
"username": grantResp.NodeGrant.Username,
}
}

View File

@@ -34,7 +34,7 @@ func (this *LogsAction) RunGet(params struct {
return
}
this.Data["tags"] = nodelogutils.FindNodeCommonTags()
this.Data["tags"] = nodelogutils.FindNodeCommonTags(this.LangCode())
this.Data["nodeId"] = params.NodeId
this.Data["dayFrom"] = params.DayFrom

View File

@@ -59,7 +59,7 @@ func (this *IndexAction) RunGet(params struct {
"id": grantResp.NodeGrant.Id,
"name": grantResp.NodeGrant.Name,
"method": grantResp.NodeGrant.Method,
"methodName": grantutils.FindGrantMethodName(grantResp.NodeGrant.Method),
"methodName": grantutils.FindGrantMethodName(grantResp.NodeGrant.Method, this.LangCode()),
"username": grantResp.NodeGrant.Username,
}
}

View File

@@ -51,7 +51,7 @@ func (this *IndexAction) RunGet(params struct {
"id": grant.Id,
"name": grant.Name,
"method": grant.Method,
"methodName": grantutils.FindGrantMethodName(grant.Method),
"methodName": grantutils.FindGrantMethodName(grant.Method, this.LangCode()),
}
}
}

View File

@@ -87,7 +87,7 @@ func (this *UpdateNodeSSHAction) RunGet(params struct {
"id": grantResp.NodeGrant.Id,
"name": grantResp.NodeGrant.Name,
"method": grantResp.NodeGrant.Method,
"methodName": grantutils.FindGrantMethodName(grantResp.NodeGrant.Method),
"methodName": grantutils.FindGrantMethodName(grantResp.NodeGrant.Method, this.LangCode()),
}
}
this.Data["grant"] = grantMap

View File

@@ -18,7 +18,7 @@ func (this *CreateAction) Init() {
}
func (this *CreateAction) RunGet(params struct{}) {
this.Data["methods"] = grantutils.AllGrantMethods()
this.Data["methods"] = grantutils.AllGrantMethods(this.LangCode())
this.Show()
}

View File

@@ -19,7 +19,7 @@ func (this *CreatePopupAction) Init() {
}
func (this *CreatePopupAction) RunGet(params struct{}) {
this.Data["methods"] = grantutils.AllGrantMethods()
this.Data["methods"] = grantutils.AllGrantMethods(this.LangCode())
this.Show()
}
@@ -88,7 +88,7 @@ func (this *CreatePopupAction) RunPost(params struct {
"id": createResp.NodeGrantId,
"name": params.Name,
"method": params.Method,
"methodName": grantutils.FindGrantMethodName(params.Method),
"methodName": grantutils.FindGrantMethodName(params.Method, this.LangCode()),
"username": params.Username,
}

View File

@@ -36,7 +36,7 @@ func (this *GrantAction) RunGet(params struct {
"id": grant.Id,
"name": grant.Name,
"method": grant.Method,
"methodName": grantutils.FindGrantMethodName(grant.Method),
"methodName": grantutils.FindGrantMethodName(grant.Method, this.LangCode()),
"username": grant.Username,
"password": strings.Repeat("*", len(grant.Password)),
"privateKey": grant.PrivateKey,

View File

@@ -1,24 +1,28 @@
package grantutils
import "github.com/iwind/TeaGo/maps"
import (
"github.com/TeaOSLab/EdgeCommon/pkg/langs"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/iwind/TeaGo/maps"
)
// 所有的认证类型
func AllGrantMethods() []maps.Map {
// AllGrantMethods 所有的认证类型
func AllGrantMethods(langCode langs.LangCode) []maps.Map {
return []maps.Map{
{
"name": "用户名+密码",
"name": langs.Message(langCode, codes.AdminNodeGrantMethodUserPassword),
"value": "user",
},
{
"name": "私钥",
"name": langs.Message(langCode, codes.AdminNodeGrantMethodPrivateKey),
"value": "privateKey",
},
}
}
// 获得对应的认证类型名称
func FindGrantMethodName(method string) string {
for _, m := range AllGrantMethods() {
// FindGrantMethodName 获得对应的认证类型名称
func FindGrantMethodName(method string, langCode langs.LangCode) string {
for _, m := range AllGrantMethods(langCode) {
if m.GetString("value") == method {
return m.GetString("name")
}

View File

@@ -62,7 +62,7 @@ func (this *IndexAction) RunGet(params struct {
"name": grant.Name,
"method": maps.Map{
"type": grant.Method,
"name": grantutils.FindGrantMethodName(grant.Method),
"name": grantutils.FindGrantMethodName(grant.Method, this.LangCode()),
},
"username": grant.Username,
"countClusters": countClusters,

View File

@@ -33,7 +33,7 @@ func (this *SelectPopupAction) RunGet(params struct {
"id": grant.Id,
"name": grant.Name,
"method": grant.Method,
"methodName": grantutils.FindGrantMethodName(grant.Method),
"methodName": grantutils.FindGrantMethodName(grant.Method, this.LangCode()),
"username": grant.Username,
"description": grant.Description,
})
@@ -55,7 +55,7 @@ func (this *SelectPopupAction) RunGet(params struct {
"id": grant.Id,
"name": grant.Name,
"method": grant.Method,
"methodName": grantutils.FindGrantMethodName(grant.Method),
"methodName": grantutils.FindGrantMethodName(grant.Method, this.LangCode()),
"username": grant.Username,
"description": grant.Description,
})
@@ -92,7 +92,7 @@ func (this *SelectPopupAction) RunPost(params struct {
"id": grant.Id,
"name": grant.Name,
"method": grant.Method,
"methodName": grantutils.FindGrantMethodName(grant.Method),
"methodName": grantutils.FindGrantMethodName(grant.Method, this.LangCode()),
}
this.Success()

View File

@@ -37,7 +37,7 @@ func (this *TestAction) RunGet(params struct {
"id": grant.Id,
"name": grant.Name,
"method": grant.Method,
"methodName": grantutils.FindGrantMethodName(grant.Method),
"methodName": grantutils.FindGrantMethodName(grant.Method, this.LangCode()),
"username": grant.Username,
"password": strings.Repeat("*", len(grant.Password)),
"privateKey": grant.PrivateKey,

View File

@@ -21,7 +21,7 @@ func (this *UpdateAction) Init() {
func (this *UpdateAction) RunGet(params struct {
GrantId int64
}) {
this.Data["methods"] = grantutils.AllGrantMethods()
this.Data["methods"] = grantutils.AllGrantMethods(this.LangCode())
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledNodeGrant(this.AdminContext(), &pb.FindEnabledNodeGrantRequest{NodeGrantId: params.GrantId})
if err != nil {
@@ -40,7 +40,7 @@ func (this *UpdateAction) RunGet(params struct {
"id": grant.Id,
"name": grant.Name,
"method": grant.Method,
"methodName": grantutils.FindGrantMethodName(grant.Method),
"methodName": grantutils.FindGrantMethodName(grant.Method, this.LangCode()),
"username": grant.Username,
"password": grant.Password,
"privateKey": grant.PrivateKey,

View File

@@ -21,7 +21,7 @@ func (this *UpdatePopupAction) Init() {
func (this *UpdatePopupAction) RunGet(params struct {
GrantId int64
}) {
this.Data["methods"] = grantutils.AllGrantMethods()
this.Data["methods"] = grantutils.AllGrantMethods(this.LangCode())
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledNodeGrant(this.AdminContext(), &pb.FindEnabledNodeGrantRequest{NodeGrantId: params.GrantId})
if err != nil {
@@ -123,7 +123,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
"id": params.GrantId,
"name": params.Name,
"method": params.Method,
"methodName": grantutils.FindGrantMethodName(params.Method),
"methodName": grantutils.FindGrantMethodName(params.Method, this.LangCode()),
"username": params.Username,
}

View File

@@ -54,7 +54,7 @@ func (this *IndexAction) RunGet(params struct {
}
// 常见标签
this.Data["tags"] = nodelogutils.FindNodeCommonTags()
this.Data["tags"] = nodelogutils.FindNodeCommonTags(this.LangCode())
// 未读数量
countUnreadResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{

View File

@@ -3,6 +3,7 @@ package log
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"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/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
@@ -41,15 +42,15 @@ func (this *IndexAction) RunGet(params struct {
this.Data["levelOptions"] = []maps.Map{
{
"code": "info",
"name": "信息",
"name": this.Lang(codes.AdminLevelInfo),
},
{
"code": "warn",
"name": "警告",
"name": this.Lang(codes.AdminLevelWarn),
},
{
"code": "error",
"name": "错误",
"name": this.Lang(codes.AdminLevelError),
},
}

View File

@@ -2,6 +2,8 @@ package certs
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
@@ -10,14 +12,15 @@ import (
)
type Helper struct {
helpers.LangHelper
}
func NewHelper() *Helper {
return &Helper{}
}
func (this *Helper) BeforeAction(actionWrapper actions.ActionWrapper) {
var action = actionWrapper.Object()
func (this *Helper) BeforeAction(actionPtr actions.ActionWrapper) {
var action = actionPtr.Object()
if action.Request.Method != http.MethodGet {
return
}
@@ -25,7 +28,7 @@ func (this *Helper) BeforeAction(actionWrapper actions.ActionWrapper) {
action.Data["teaMenu"] = "servers"
var countOCSP int64 = 0
parentAction, ok := actionWrapper.(actionutils.ActionInterface)
parentAction, ok := actionPtr.(actionutils.ActionInterface)
if ok {
countOCSPResp, err := parentAction.RPC().SSLCertRPC().CountAllSSLCertsWithOCSPError(parentAction.AdminContext(), &pb.CountAllSSLCertsWithOCSPErrorRequest{})
if err == nil {
@@ -33,19 +36,19 @@ func (this *Helper) BeforeAction(actionWrapper actions.ActionWrapper) {
}
}
var ocspMenuName = "OCSP日志"
var ocspMenuName = this.Lang(actionPtr, codes.AdminCertMenuOCSP)
if countOCSP > 0 {
ocspMenuName += "(" + types.String(countOCSP) + ")"
}
var menu = []maps.Map{
{
"name": "证书",
"name": this.Lang(actionPtr, codes.AdminCertMenuCerts),
"url": "/servers/certs",
"isActive": action.Data.GetString("leftMenuItem") == "cert",
},
{
"name": "申请证书",
"name": this.Lang(actionPtr, codes.AdminCertMenuApply),
"url": "/servers/certs/acme",
"isActive": action.Data.GetString("leftMenuItem") == "acme",
},

View File

@@ -3,6 +3,7 @@ package waf
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
@@ -41,14 +42,14 @@ func (this *CreateSetPopupAction) RunGet(params struct {
// 一些配置
this.Data["connectors"] = []maps.Map{
{
"name": "和(AND)",
"name": this.Lang(codes.AdminWAFConnectorAnd),
"value": firewallconfigs.HTTPFirewallRuleConnectorAnd,
"description": "所有规则都满足才视为匹配",
"description": this.Lang(codes.AdminWAFConnectorAndDescription),
},
{
"name": "或(OR)",
"name": this.Lang(codes.AdminWAFConnectorOr),
"value": firewallconfigs.HTTPFirewallRuleConnectorOr,
"description": "任一规则满足了就视为匹配",
"description": this.Lang(codes.AdminWAFConnectorOrDescription),
},
}

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
@@ -45,14 +46,14 @@ func (this *UpdateSetPopupAction) RunGet(params struct {
// 一些配置
this.Data["connectors"] = []maps.Map{
{
"name": "和(AND)",
"name": this.Lang(codes.AdminWAFConnectorAnd),
"value": firewallconfigs.HTTPFirewallRuleConnectorAnd,
"description": "所有规则都满足才视为匹配",
"description": this.Lang(codes.AdminWAFConnectorAndDescription),
},
{
"name": "或(OR)",
"name": this.Lang(codes.AdminWAFConnectorOr),
"value": firewallconfigs.HTTPFirewallRuleConnectorOr,
"description": "任一规则满足了就视为匹配",
"description": this.Lang(codes.AdminWAFConnectorOrDescription),
},
}

View File

@@ -5,14 +5,15 @@
package servergrouputils
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
func filterMenuItems(leftMenuItems []maps.Map, groupId int64, urlPrefix string, menuItem string, configInfoResp *pb.FindEnabledServerGroupConfigInfoResponse) []maps.Map {
func filterMenuItems(leftMenuItems []maps.Map, groupId int64, urlPrefix string, menuItem string, configInfoResp *pb.FindEnabledServerGroupConfigInfoResponse, parent *actionutils.ParentAction) []maps.Map {
return leftMenuItems
}
func filterMenuItems2(leftMenuItems []maps.Map, groupId int64, urlPrefix string, menuItem string, configInfoResp *pb.FindEnabledServerGroupConfigInfoResponse) []maps.Map {
func filterMenuItems2(leftMenuItems []maps.Map, groupId int64, urlPrefix string, menuItem string, configInfoResp *pb.FindEnabledServerGroupConfigInfoResponse, parent *actionutils.ParentAction) []maps.Map {
return leftMenuItems
}

View File

@@ -5,6 +5,7 @@ package servergrouputils
import (
"errors"
"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/maps"
"github.com/iwind/TeaGo/types"
@@ -37,39 +38,39 @@ func InitGroup(parent *actionutils.ParentAction, groupId int64, menuItem string)
var urlPrefix = "/servers/groups/group/settings"
var leftMenuItems = []maps.Map{
{
"name": "HTTP代理",
"name": parent.Lang(codes.AdminServerMenuSettingHTTPProxy),
"url": urlPrefix + "/httpReverseProxy?groupId=" + types.String(groupId),
"isActive": menuItem == "httpReverseProxy",
"isOn": configInfoResp.HasHTTPReverseProxy,
},
{
"name": "TCP代理",
"name": parent.Lang(codes.AdminServerMenuSettingTCPProxy),
"url": urlPrefix + "/tcpReverseProxy?groupId=" + types.String(groupId),
"isActive": menuItem == "tcpReverseProxy",
"isOn": configInfoResp.HasTCPReverseProxy,
},
{
"name": "UDP代理",
"name": parent.Lang(codes.AdminServerMenuSettingUDPProxy),
"url": urlPrefix + "/udpReverseProxy?groupId=" + types.String(groupId),
"isActive": menuItem == "udpReverseProxy",
"isOn": configInfoResp.HasUDPReverseProxy,
},
}
leftMenuItems = filterMenuItems(leftMenuItems, groupId, urlPrefix, menuItem, configInfoResp)
leftMenuItems = filterMenuItems(leftMenuItems, groupId, urlPrefix, menuItem, configInfoResp, parent)
leftMenuItems = append(leftMenuItems, maps.Map{
"name": "-",
"url": "",
})
leftMenuItems = append(leftMenuItems, maps.Map{
"name": "访客IP地址",
"name": parent.Lang(codes.AdminServerMenuSettingClientIP),
"url": urlPrefix + "/remoteAddr?groupId=" + types.String(groupId),
"isActive": menuItem == "remoteAddr",
"isOn": configInfoResp.HasRemoteAddrConfig,
})
leftMenuItems = filterMenuItems2(leftMenuItems, groupId, urlPrefix, menuItem, configInfoResp)
leftMenuItems = filterMenuItems2(leftMenuItems, groupId, urlPrefix, menuItem, configInfoResp, parent)
parent.Data["leftMenuItems"] = leftMenuItems
}

View File

@@ -2,6 +2,8 @@ package locationutils
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
@@ -10,6 +12,7 @@ import (
)
type LocationHelper struct {
helpers.LangHelper
}
func NewLocationHelper() *LocationHelper {
@@ -48,31 +51,31 @@ func (this *LocationHelper) BeforeAction(actionPtr actions.ActionWrapper) {
}
// 左侧菜单
action.Data["tinyLeftMenuItems"] = this.createMenus(serverIdString, locationIdString, action.Data.GetString("tinyMenuItem"), currentLocationConfig)
action.Data["tinyLeftMenuItems"] = this.createMenus(serverIdString, locationIdString, action.Data.GetString("tinyMenuItem"), currentLocationConfig, actionPtr)
}
func (this *LocationHelper) createMenus(serverIdString string, locationIdString string, secondMenuItem string, locationConfig *serverconfigs.HTTPLocationConfig) []maps.Map {
func (this *LocationHelper) createMenus(serverIdString string, locationIdString string, secondMenuItem string, locationConfig *serverconfigs.HTTPLocationConfig, actionPtr actions.ActionWrapper) []maps.Map {
menuItems := []maps.Map{}
menuItems = append(menuItems, maps.Map{
"name": "基本信息",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingBasic),
"url": "/servers/server/settings/locations/location?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "basic",
"isOff": locationConfig != nil && !locationConfig.IsOn,
})
menuItems = append(menuItems, maps.Map{
"name": "HTTP",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingHTTP),
"url": "/servers/server/settings/locations/http?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "http",
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.RedirectToHttps != nil && locationConfig.Web.RedirectToHttps.IsPrior,
})
menuItems = append(menuItems, maps.Map{
"name": "源站",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingOrigins),
"url": "/servers/server/settings/locations/reverseProxy?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "reverseProxy",
"isOn": locationConfig != nil && locationConfig.ReverseProxyRef != nil && locationConfig.ReverseProxyRef.IsPrior,
})
menuItems = filterMenuItems1(locationConfig, menuItems, serverIdString, locationIdString, secondMenuItem)
menuItems = this.filterMenuItems1(locationConfig, menuItems, serverIdString, locationIdString, secondMenuItem, actionPtr)
menuItems = append(menuItems, maps.Map{
"name": "-",
@@ -80,103 +83,103 @@ func (this *LocationHelper) createMenus(serverIdString string, locationIdString
"isActive": false,
})
menuItems = append(menuItems, maps.Map{
"name": "重写规则",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingRewriteRules),
"url": "/servers/server/settings/locations/rewrite?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "rewrite",
"isOn": locationConfig != nil && locationConfig.Web != nil && len(locationConfig.Web.RewriteRefs) > 0,
})
menuItems = append(menuItems, maps.Map{
"name": "WAF",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingWAF),
"url": "/servers/server/settings/locations/waf?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "waf",
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.FirewallRef != nil && locationConfig.Web.FirewallRef.IsPrior,
})
menuItems = append(menuItems, maps.Map{
"name": "缓存",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingCache),
"url": "/servers/server/settings/locations/cache?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "cache",
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.Cache != nil && locationConfig.Web.Cache.IsPrior && locationConfig.Web.Cache.IsOn,
})
menuItems = append(menuItems, maps.Map{
"name": "访问鉴权",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingAuth),
"url": "/servers/server/settings/locations/access?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "access",
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.Auth != nil && locationConfig.Web.Auth.IsPrior,
})
menuItems = append(menuItems, maps.Map{
"name": "防盗链",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingReferers),
"url": "/servers/server/settings/locations/referers?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "referer",
"isOn": locationConfig.Web != nil && locationConfig.Web.Referers != nil && locationConfig.Web.Referers.IsPrior,
})
menuItems = append(menuItems, maps.Map{
"name": "UA名单",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingUserAgents),
"url": "/servers/server/settings/locations/userAgent?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "userAgent",
"isOn": locationConfig.Web != nil && locationConfig.Web.UserAgent != nil && locationConfig.Web.UserAgent.IsPrior,
})
menuItems = append(menuItems, maps.Map{
"name": "字符编码",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingCharset),
"url": "/servers/server/settings/locations/charset?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "charset",
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.Charset != nil && locationConfig.Web.Charset.IsPrior,
})
menuItems = append(menuItems, maps.Map{
"name": "访问日志",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingAccessLog),
"url": "/servers/server/settings/locations/accessLog?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "accessLog",
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.AccessLogRef != nil && locationConfig.Web.AccessLogRef.IsPrior,
})
menuItems = append(menuItems, maps.Map{
"name": "统计",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingStat),
"url": "/servers/server/settings/locations/stat?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "stat",
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.StatRef != nil && locationConfig.Web.StatRef.IsPrior,
})
menuItems = append(menuItems, maps.Map{
"name": "内容压缩",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingCompress),
"url": "/servers/server/settings/locations/compression?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "compression",
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.Compression != nil && locationConfig.Web.Compression.IsPrior,
})
menuItems = append(menuItems, maps.Map{
"name": "自定义页面",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingPages),
"url": "/servers/server/settings/locations/pages?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "pages",
"isOn": locationConfig != nil && locationConfig.Web != nil && (len(locationConfig.Web.Pages) > 0 || (locationConfig.Web.Shutdown != nil && locationConfig.Web.Shutdown.IsPrior)),
})
menuItems = append(menuItems, maps.Map{
"name": "HTTP Header",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingHTTPHeaders),
"url": "/servers/server/settings/locations/headers?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "header",
"isOn": locationConfig != nil && this.hasHTTPHeaders(locationConfig.Web),
})
menuItems = append(menuItems, maps.Map{
"name": "Websocket",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingWebsocket),
"url": "/servers/server/settings/locations/websocket?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "websocket",
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.WebsocketRef != nil && locationConfig.Web.WebsocketRef.IsPrior,
})
menuItems = append(menuItems, maps.Map{
"name": "WebP",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingWebP),
"url": "/servers/server/settings/locations/webp?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "webp",
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.WebP != nil && locationConfig.Web.WebP.IsPrior,
})
menuItems = append(menuItems, maps.Map{
"name": "静态分发",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingRoot),
"url": "/servers/server/settings/locations/web?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "web",
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.Root != nil && locationConfig.Web.Root.IsPrior,
})
menuItems = append(menuItems, maps.Map{
"name": "Fastcgi",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingFastcgi),
"url": "/servers/server/settings/locations/fastcgi?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "fastcgi",
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.FastcgiRef != nil && locationConfig.Web.FastcgiRef.IsPrior,
})
menuItems = filterMenuItems2(locationConfig, menuItems, serverIdString, locationIdString, secondMenuItem)
menuItems = this.filterMenuItems2(locationConfig, menuItems, serverIdString, locationIdString, secondMenuItem, actionPtr)
menuItems = append(menuItems, maps.Map{
"name": "-",
@@ -185,14 +188,14 @@ func (this *LocationHelper) createMenus(serverIdString string, locationIdString
})
menuItems = append(menuItems, maps.Map{
"name": "访客IP地址",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingClientIP),
"url": "/servers/server/settings/locations/remoteAddr?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "remoteAddr",
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.RemoteAddr != nil && locationConfig.Web.RemoteAddr.IsOn,
})
menuItems = append(menuItems, maps.Map{
"name": "请求限制",
"name": this.Lang(actionPtr, codes.AdminServerMenuSettingRequestLimit),
"url": "/servers/server/settings/locations/requestLimit?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "requestLimit",
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.RequestLimit != nil && locationConfig.Web.RequestLimit.IsOn,

View File

@@ -5,13 +5,14 @@ package locationutils
import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
func filterMenuItems1(locationConfig *serverconfigs.HTTPLocationConfig, menuItems []maps.Map, serverIdString string, locationIdString string, secondMenuItem string) []maps.Map {
func (this *LocationHelper) filterMenuItems1(locationConfig *serverconfigs.HTTPLocationConfig, menuItems []maps.Map, serverIdString string, locationIdString string, secondMenuItem string, actionPtr actions.ActionWrapper) []maps.Map {
return menuItems
}
func filterMenuItems2(locationConfig *serverconfigs.HTTPLocationConfig, menuItems []maps.Map, serverIdString string, locationIdString string, secondMenuItem string) []maps.Map {
func (this *LocationHelper) filterMenuItems2(locationConfig *serverconfigs.HTTPLocationConfig, menuItems []maps.Map, serverIdString string, locationIdString string, secondMenuItem string, actionPtr actions.ActionWrapper) []maps.Map {
return menuItems
}