diff --git a/internal/web/actions/default/servers/groups/group/servergrouputils/utils.go b/internal/web/actions/default/servers/groups/group/servergrouputils/utils.go index 48f1aad2..f2ac2a3d 100644 --- a/internal/web/actions/default/servers/groups/group/servergrouputils/utils.go +++ b/internal/web/actions/default/servers/groups/group/servergrouputils/utils.go @@ -4,6 +4,7 @@ package servergrouputils import ( "errors" + teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/maps" @@ -35,75 +36,109 @@ func InitGroup(parent *actionutils.ParentAction, groupId int64, menuItem string) } var urlPrefix = "/servers/groups/group/settings" - parent.Data["leftMenuItems"] = []maps.Map{ - /**{ - "name": "Web设置", - "url": urlPrefix + "/web?groupId=" + types.String(groupId), - "isActive": menuItem == "web", - },**/ + var leftMenuItems = []maps.Map{ { - "name": "HTTP反向代理", + "name": "HTTP代理", "url": urlPrefix + "/httpReverseProxy?groupId=" + types.String(groupId), "isActive": menuItem == "httpReverseProxy", "isOn": configInfoResp.HasHTTPReverseProxy, }, { - "name": "TCP反向代理", + "name": "TCP代理", "url": urlPrefix + "/tcpReverseProxy?groupId=" + types.String(groupId), "isActive": menuItem == "tcpReverseProxy", "isOn": configInfoResp.HasTCPReverseProxy, }, { - "name": "UDP反向代理", + "name": "UDP代理", "url": urlPrefix + "/udpReverseProxy?groupId=" + types.String(groupId), "isActive": menuItem == "udpReverseProxy", "isOn": configInfoResp.HasUDPReverseProxy, }, - /**{ - "name": "-", - "url": "", - }, - { - "name": "WAF", - "url": urlPrefix + "/waf?groupId=" + types.String(groupId), - "isActive": menuItem == "waf", - }, - { - "name": "缓存", - "url": urlPrefix + "/cache?groupId=" + types.String(groupId), - "isActive": menuItem == "cache", - }, - { - "name": "访问日志", - "url": urlPrefix + "/accessLog?groupId=" + types.String(groupId), - "isActive": menuItem == "accessLog", - }, - { - "name": "统计", - "url": urlPrefix + "/stat?groupId=" + types.String(groupId), - "isActive": menuItem == "stat", - }, - { - "name": "Gzip压缩", - "url": urlPrefix + "/gzip?groupId=" + types.String(groupId), - "isActive": menuItem == "gzip", - }, - { - "name": "特殊页面", - "url": urlPrefix + "/pages?groupId=" + types.String(groupId), - "isActive": menuItem == "page", - }, - { - "name": "HTTP Header", - "url": urlPrefix + "/headers?groupId=" + types.String(groupId), - "isActive": menuItem == "header", - }, - { - "name": "Websocket", - "url": urlPrefix + "/websocket?groupId=" + types.String(groupId), - "isActive": menuItem == "websocket", - },**/ } + + if teaconst.IsPlus { + leftMenuItems = append([]maps.Map{ + { + "name": "Web设置", + "url": urlPrefix + "/web?groupId=" + types.String(groupId), + "isActive": menuItem == "web", + "isOn": configInfoResp.HasRootConfig, + }, + }, leftMenuItems...) + leftMenuItems = append(leftMenuItems, []maps.Map{ + { + "name": "-", + "url": "", + }, + { + "name": "WAF", + "url": urlPrefix + "/waf?groupId=" + types.String(groupId), + "isActive": menuItem == "waf", + "isOn": configInfoResp.HasWAFConfig, + }, + { + "name": "缓存", + "url": urlPrefix + "//cache?groupId=" + types.String(groupId), + "isActive": menuItem == "cache", + "isOn": configInfoResp.HasCacheConfig, + }, + { + "name": "字符编码", + "url": urlPrefix + "/charset?groupId=" + types.String(groupId), + "isActive": menuItem == "charset", + "isOn": configInfoResp.HasCharsetConfig, + }, + { + "name": "访问日志", + "url": urlPrefix + "/accessLog?groupId=" + types.String(groupId), + "isActive": menuItem == "accessLog", + "isOn": configInfoResp.HasAccessLogConfig, + }, + { + "name": "统计", + "url": urlPrefix + "/stat?groupId=" + types.String(groupId), + "isActive": menuItem == "stat", + "isOn": configInfoResp.HasStatConfig, + }, + { + "name": "内容压缩", + "url": urlPrefix + "/compression?groupId=" + types.String(groupId), + "isActive": menuItem == "compression", + "isOn": configInfoResp.HasCompressionConfig, + }, + { + "name": "HTTP Header", + "url": urlPrefix + "/headers?groupId=" + types.String(groupId), + "isActive": menuItem == "headers", + "isOn": configInfoResp.HasRequestHeadersConfig || configInfoResp.HasResponseHeadersConfig, + }, + { + "name": "Websocket", + "url": urlPrefix + "/websocket?groupId=" + types.String(groupId), + "isActive": menuItem == "websocket", + "isOn": configInfoResp.HasWebsocketConfig, + }, + { + "name": "WebP", + "url": urlPrefix + "/webp?groupId=" + types.String(groupId), + "isActive": menuItem == "webp", + "isOn": configInfoResp.HasWebPConfig, + }, + }...) + } + + leftMenuItems = append(leftMenuItems, maps.Map{ + "name": "-", + "url": "", + }) + leftMenuItems = append(leftMenuItems, maps.Map{ + "name": "访客IP地址", + "url": urlPrefix + "/remoteAddr?groupId=" + types.String(groupId), + "isActive": menuItem == "remoteAddr", + "isOn": configInfoResp.HasRemoteAddrConfig, + }) + parent.Data["leftMenuItems"] = leftMenuItems } return group, nil diff --git a/internal/web/actions/default/servers/groups/group/settings/accessLog/index.go b/internal/web/actions/default/servers/groups/group/settings/accessLog/index.go new file mode 100644 index 00000000..9b22dce6 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/accessLog/index.go @@ -0,0 +1,68 @@ +package accessLog + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "setting", "index") + this.SecondMenu("accessLog") +} + +func (this *IndexAction) RunGet(params struct { + GroupId int64 +}) { + _, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "accessLog") + if err != nil { + this.ErrorPage(err) + return + } + + // 获取配置 + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerGroupId(this.AdminContext(), params.GroupId) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["webId"] = webConfig.Id + this.Data["accessLogConfig"] = webConfig.AccessLogRef + + // 通用变量 + this.Data["fields"] = serverconfigs.HTTPAccessLogFields + this.Data["defaultFieldCodes"] = serverconfigs.HTTPAccessLogDefaultFieldsCodes + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + WebId int64 + AccessLogJSON []byte + + Must *actions.Must +}) { + // 日志 + defer this.CreateLog(oplogs.LevelInfo, "修改Web %d 的访问日志设置", params.WebId) + + // TODO 检查参数 + + _, err := this.RPC().HTTPWebRPC().UpdateHTTPWebAccessLog(this.AdminContext(), &pb.UpdateHTTPWebAccessLogRequest{ + WebId: params.WebId, + AccessLogJSON: params.AccessLogJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/accessLog/init.go b/internal/web/actions/default/servers/groups/group/settings/accessLog/init.go new file mode 100644 index 00000000..652cddd3 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/accessLog/init.go @@ -0,0 +1,19 @@ +package accessLog + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" + "github.com/iwind/TeaGo" +) + +func init() { + TeaGo.BeforeStart(func(server *TeaGo.Server) { + server. + Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). + Data("teaMenu", "servers"). + Data("teaSubMenu", "group"). + Prefix("/servers/groups/group/settings/accessLog"). + GetPost("", new(IndexAction)). + EndAll() + }) +} diff --git a/internal/web/actions/default/servers/groups/group/settings/cache/index.go b/internal/web/actions/default/servers/groups/group/settings/cache/index.go new file mode 100644 index 00000000..2e7890bf --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/cache/index.go @@ -0,0 +1,88 @@ +package cache + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "setting", "index") + this.SecondMenu("cache") +} + +func (this *IndexAction) RunGet(params struct { + GroupId int64 +}) { + _, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "cache") + if err != nil { + this.ErrorPage(err) + return + } + + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerGroupId(this.AdminContext(), params.GroupId) + if err != nil { + this.ErrorPage(err) + return + } + + this.Data["webId"] = webConfig.Id + this.Data["cacheConfig"] = webConfig.Cache + + this.Data["cachePolicy"] = nil + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + WebId int64 + CacheJSON []byte + + Must *actions.Must +}) { + // 日志 + defer this.CreateLog(oplogs.LevelInfo, "修改Web %d 的缓存设置", params.WebId) + + // 校验配置 + cacheConfig := &serverconfigs.HTTPCacheConfig{} + err := json.Unmarshal(params.CacheJSON, cacheConfig) + if err != nil { + this.ErrorPage(err) + return + } + err = cacheConfig.Init() + if err != nil { + this.Fail("检查配置失败:" + err.Error()) + } + + // 去除不必要的部分 + for _, cacheRef := range cacheConfig.CacheRefs { + cacheRef.CachePolicy = nil + } + + cacheJSON, err := json.Marshal(cacheConfig) + if err != nil { + this.ErrorPage(err) + return + } + + _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{ + WebId: params.WebId, + CacheJSON: cacheJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/cache/init.go b/internal/web/actions/default/servers/groups/group/settings/cache/init.go new file mode 100644 index 00000000..92a1347c --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/cache/init.go @@ -0,0 +1,21 @@ +package cache + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" + "github.com/iwind/TeaGo" +) + +func init() { + TeaGo.BeforeStart(func(server *TeaGo.Server) { + server. + Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). + Data("teaMenu", "servers"). + Data("teaSubMenu", "group"). + Prefix("/servers/groups/group/settings/cache"). + GetPost("", new(IndexAction)). + GetPost("/purge", new(PurgeAction)). + GetPost("/preheat", new(PreheatAction)). + EndAll() + }) +} diff --git a/internal/web/actions/default/servers/groups/group/settings/cache/preheat.go b/internal/web/actions/default/servers/groups/group/settings/cache/preheat.go new file mode 100644 index 00000000..b9099d73 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/cache/preheat.go @@ -0,0 +1,143 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package cache + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils" + "github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/lists" + "strings" +) + +type PreheatAction struct { + actionutils.ParentAction +} + +func (this *PreheatAction) Init() { + this.Nav("", "setting", "preheat") + this.SecondMenu("cache") +} + +func (this *PreheatAction) RunGet(params struct { + ServerId int64 +}) { + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) + if err != nil { + this.ErrorPage(err) + return + } + + this.Data["webId"] = webConfig.Id + this.Data["webConfig"] = webConfig + + this.Show() +} + +func (this *PreheatAction) RunPost(params struct { + ServerId int64 + WebId int64 + Keys string + + Must *actions.Must +}) { + + // 创建日志 + defer this.CreateLog(oplogs.LevelInfo, "预热服务 %d 缓存", params.ServerId) + + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithId(this.AdminContext(), params.WebId) + if err != nil { + this.ErrorPage(err) + return + } + if webConfig == nil { + this.NotFound("httpWeb", params.WebId) + return + } + var cache = webConfig.Cache + if cache == nil || !cache.IsOn { + this.Fail("当前没有开启缓存") + } + + serverResp, err := this.RPC().ServerRPC().FindEnabledUserServerBasic(this.AdminContext(), &pb.FindEnabledUserServerBasicRequest{ServerId: params.ServerId}) + if err != nil { + this.ErrorPage(err) + return + } + var server = serverResp.Server + if server == nil || server.NodeCluster == nil { + this.NotFound("server", params.ServerId) + return + } + + var clusterId = server.NodeCluster.Id + + clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId}) + if err != nil { + this.ErrorPage(err) + return + } + var cluster = clusterResp.NodeCluster + if cluster == nil { + this.NotFound("nodeCluster", clusterId) + return + } + var cachePolicyId = cluster.HttpCachePolicyId + if cachePolicyId == 0 { + this.Fail("当前集群没有设置缓存策略") + } + + cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{HttpCachePolicyId: cachePolicyId}) + if err != nil { + this.ErrorPage(err) + return + } + cachePolicyJSON := cachePolicyResp.HttpCachePolicyJSON + if len(cachePolicyJSON) == 0 { + this.Fail("找不到要操作的缓存策略") + } + + if len(params.Keys) == 0 { + this.Fail("请输入要预热的Key列表") + } + + realKeys := []string{} + for _, key := range strings.Split(params.Keys, "\n") { + key = strings.TrimSpace(key) + if len(key) == 0 { + continue + } + if lists.ContainsString(realKeys, key) { + continue + } + realKeys = append(realKeys, key) + } + + // 发送命令 + msg := &messageconfigs.PreheatCacheMessage{ + CachePolicyJSON: cachePolicyJSON, + Keys: realKeys, + } + results, err := nodeutils.SendMessageToCluster(this.AdminContext(), clusterId, messageconfigs.MessageCodePreheatCache, msg, 300) + if err != nil { + this.ErrorPage(err) + return + } + + isAllOk := true + for _, result := range results { + if !result.IsOK { + isAllOk = false + break + } + } + + this.Data["isAllOk"] = isAllOk + this.Data["results"] = results + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/cache/purge.go b/internal/web/actions/default/servers/groups/group/settings/cache/purge.go new file mode 100644 index 00000000..e18fe292 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/cache/purge.go @@ -0,0 +1,149 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package cache + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils" + "github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/lists" + "strings" +) + +type PurgeAction struct { + actionutils.ParentAction +} + +func (this *PurgeAction) Init() { + this.Nav("", "setting", "purge") + this.SecondMenu("cache") +} + +func (this *PurgeAction) RunGet(params struct { + ServerId int64 +}) { + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) + if err != nil { + this.ErrorPage(err) + return + } + + this.Data["webId"] = webConfig.Id + this.Data["webConfig"] = webConfig + + this.Show() +} + +func (this *PurgeAction) RunPost(params struct { + ServerId int64 + WebId int64 + Type string + Keys string + + Must *actions.Must +}) { + + // 创建日志 + defer this.CreateLog(oplogs.LevelInfo, "删除服务 %d 缓存", params.ServerId) + + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithId(this.AdminContext(), params.WebId) + if err != nil { + this.ErrorPage(err) + return + } + if webConfig == nil { + this.NotFound("httpWeb", params.WebId) + return + } + var cache = webConfig.Cache + if cache == nil || !cache.IsOn { + this.Fail("当前没有开启缓存") + } + + serverResp, err := this.RPC().ServerRPC().FindEnabledUserServerBasic(this.AdminContext(), &pb.FindEnabledUserServerBasicRequest{ServerId: params.ServerId}) + if err != nil { + this.ErrorPage(err) + return + } + var server = serverResp.Server + if server == nil || server.NodeCluster == nil { + this.NotFound("server", params.ServerId) + return + } + + var clusterId = server.NodeCluster.Id + + clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId}) + if err != nil { + this.ErrorPage(err) + return + } + var cluster = clusterResp.NodeCluster + if cluster == nil { + this.NotFound("nodeCluster", clusterId) + return + } + var cachePolicyId = cluster.HttpCachePolicyId + if cachePolicyId == 0 { + this.Fail("当前集群没有设置缓存策略") + } + + cachePolicyResp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPCachePolicyConfigRequest{HttpCachePolicyId: cachePolicyId}) + if err != nil { + this.ErrorPage(err) + return + } + cachePolicyJSON := cachePolicyResp.HttpCachePolicyJSON + if len(cachePolicyJSON) == 0 { + this.Fail("找不到要操作的缓存策略") + } + + if len(params.Keys) == 0 { + this.Fail("请输入要删除的Key列表") + } + + realKeys := []string{} + for _, key := range strings.Split(params.Keys, "\n") { + key = strings.TrimSpace(key) + if len(key) == 0 { + continue + } + if lists.ContainsString(realKeys, key) { + continue + } + realKeys = append(realKeys, key) + } + + // 发送命令 + msg := &messageconfigs.PurgeCacheMessage{ + CachePolicyJSON: cachePolicyJSON, + Keys: realKeys, + } + if params.Type == "prefix" { + msg.Type = messageconfigs.PurgeCacheMessageTypeDir + } else { + msg.Type = messageconfigs.PurgeCacheMessageTypeFile + } + results, err := nodeutils.SendMessageToCluster(this.AdminContext(), clusterId, messageconfigs.MessageCodePurgeCache, msg, 10) + if err != nil { + this.ErrorPage(err) + return + } + + isAllOk := true + for _, result := range results { + if !result.IsOK { + isAllOk = false + break + } + } + + this.Data["isAllOk"] = isAllOk + this.Data["results"] = results + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/charset/index.go b/internal/web/actions/default/servers/groups/group/settings/charset/index.go new file mode 100644 index 00000000..9ed66823 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/charset/index.go @@ -0,0 +1,64 @@ +package charset + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils" + "github.com/TeaOSLab/EdgeCommon/pkg/configutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "setting", "index") + this.SecondMenu("charset") +} + +func (this *IndexAction) RunGet(params struct { + GroupId int64 +}) { + _, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "charset") + if err != nil { + this.ErrorPage(err) + return + } + + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerGroupId(this.AdminContext(), params.GroupId) + if err != nil { + this.ErrorPage(err) + return + } + + this.Data["webId"] = webConfig.Id + this.Data["charsetConfig"] = webConfig.Charset + + this.Data["usualCharsets"] = configutils.UsualCharsets + this.Data["allCharsets"] = configutils.AllCharsets + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + WebId int64 + CharsetJSON []byte + + Must *actions.Must +}) { + defer this.CreateLog(oplogs.LevelInfo, "修改Web %d 的字符集设置", params.WebId) + + _, err := this.RPC().HTTPWebRPC().UpdateHTTPWebCharset(this.AdminContext(), &pb.UpdateHTTPWebCharsetRequest{ + WebId: params.WebId, + CharsetJSON: params.CharsetJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/charset/init.go b/internal/web/actions/default/servers/groups/group/settings/charset/init.go new file mode 100644 index 00000000..d5818436 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/charset/init.go @@ -0,0 +1,19 @@ +package charset + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" + "github.com/iwind/TeaGo" +) + +func init() { + TeaGo.BeforeStart(func(server *TeaGo.Server) { + server. + Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). + Data("teaMenu", "servers"). + Data("teaSubMenu", "group"). + Prefix("/servers/groups/group/settings/charset"). + GetPost("", new(IndexAction)). + EndAll() + }) +} diff --git a/internal/web/actions/default/servers/groups/group/settings/compression/index.go b/internal/web/actions/default/servers/groups/group/settings/compression/index.go new file mode 100644 index 00000000..1328f325 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/compression/index.go @@ -0,0 +1,78 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package compression + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "setting", "index") + this.SecondMenu("compression") +} + +func (this *IndexAction) RunGet(params struct { + GroupId int64 +}) { + _, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "compression") + if err != nil { + this.ErrorPage(err) + return + } + + // WebId + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerGroupId(this.AdminContext(), params.GroupId) + if err != nil { + this.ErrorPage(err) + return + } + + this.Data["webId"] = webConfig.Id + + this.Data["compressionConfig"] = webConfig.Compression + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + WebId int64 + CompressionJSON []byte + + Must *actions.Must + CSRF *actionutils.CSRF +}) { + defer this.CreateLogInfo("修改Web %d 的压缩设置", params.WebId) + + // 校验配置 + var compressionConfig = &serverconfigs.HTTPCompressionConfig{} + err := json.Unmarshal(params.CompressionJSON, compressionConfig) + if err != nil { + this.Fail("配置校验失败:" + err.Error()) + } + + err = compressionConfig.Init() + if err != nil { + this.Fail("配置校验失败:" + err.Error()) + } + + _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCompression(this.AdminContext(), &pb.UpdateHTTPWebCompressionRequest{ + WebId: params.WebId, + CompressionJSON: params.CompressionJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/compression/init.go b/internal/web/actions/default/servers/groups/group/settings/compression/init.go new file mode 100644 index 00000000..d7441868 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/compression/init.go @@ -0,0 +1,19 @@ +package compression + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" + "github.com/iwind/TeaGo" +) + +func init() { + TeaGo.BeforeStart(func(server *TeaGo.Server) { + server. + Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). + Data("teaMenu", "servers"). + Data("teaSubMenu", "group"). + Prefix("/servers/groups/group/settings/compression"). + GetPost("", new(IndexAction)). + EndAll() + }) +} diff --git a/internal/web/actions/default/servers/groups/group/settings/headers/index.go b/internal/web/actions/default/servers/groups/group/settings/headers/index.go new file mode 100644 index 00000000..590902e7 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/headers/index.go @@ -0,0 +1,158 @@ +package headers + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "setting", "index") + this.SecondMenu("header") +} + +func (this *IndexAction) RunGet(params struct { + GroupId int64 +}) { + _, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "headers") + if err != nil { + this.ErrorPage(err) + return + } + + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerGroupId(this.AdminContext(), params.GroupId) + if err != nil { + this.ErrorPage(err) + return + } + webId := webConfig.Id + this.Data["webId"] = webId + + isChanged := false + if webConfig.RequestHeaderPolicy == nil { + createHeaderPolicyResp, err := this.RPC().HTTPHeaderPolicyRPC().CreateHTTPHeaderPolicy(this.AdminContext(), &pb.CreateHTTPHeaderPolicyRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + headerPolicyId := createHeaderPolicyResp.HeaderPolicyId + ref := &shared.HTTPHeaderPolicyRef{ + IsPrior: false, + IsOn: true, + HeaderPolicyId: headerPolicyId, + } + refJSON, err := json.Marshal(ref) + if err != nil { + this.ErrorPage(err) + return + } + _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeader(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderRequest{ + WebId: webId, + HeaderJSON: refJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + isChanged = true + } + if webConfig.ResponseHeaderPolicy == nil { + createHeaderPolicyResp, err := this.RPC().HTTPHeaderPolicyRPC().CreateHTTPHeaderPolicy(this.AdminContext(), &pb.CreateHTTPHeaderPolicyRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + headerPolicyId := createHeaderPolicyResp.HeaderPolicyId + ref := &shared.HTTPHeaderPolicyRef{ + IsPrior: false, + IsOn: true, + HeaderPolicyId: headerPolicyId, + } + refJSON, err := json.Marshal(ref) + if err != nil { + this.ErrorPage(err) + return + } + _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeader(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderRequest{ + WebId: webId, + HeaderJSON: refJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + isChanged = true + } + + // 重新获取配置 + if isChanged { + webConfig, err = dao.SharedHTTPWebDAO.FindWebConfigWithServerGroupId(this.AdminContext(), params.GroupId) + if err != nil { + this.ErrorPage(err) + return + } + } + + this.Data["requestHeaderRef"] = webConfig.RequestHeaderPolicyRef + this.Data["requestHeaderPolicy"] = webConfig.RequestHeaderPolicy + this.Data["responseHeaderRef"] = webConfig.ResponseHeaderPolicyRef + this.Data["responseHeaderPolicy"] = webConfig.ResponseHeaderPolicy + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + WebId int64 + Type string + RequestHeaderJSON []byte + ResponseHeaderJSON []byte + + Must *actions.Must +}) { + defer this.CreateLogInfo("修改Web %d 的Header设置", params.WebId) + + switch params.Type { + case "request": + // 检查配置 + var requestHeaderRef = &shared.HTTPHeaderPolicyRef{} + err := json.Unmarshal(params.RequestHeaderJSON, requestHeaderRef) + if err != nil { + this.Fail("请求Header配置校验失败:" + err.Error() + ", JSON: " + string(params.RequestHeaderJSON)) + } + + _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeader(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderRequest{ + WebId: params.WebId, + HeaderJSON: params.RequestHeaderJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + case "response": + // 校验配置 + var responseHeaderRef = &shared.HTTPHeaderPolicyRef{} + err := json.Unmarshal(params.ResponseHeaderJSON, responseHeaderRef) + if err != nil { + this.Fail("响应Header配置校验失败:" + err.Error() + ", JSON: " + string(params.ResponseHeaderJSON)) + } + + _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeader(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderRequest{ + WebId: params.WebId, + HeaderJSON: params.ResponseHeaderJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/headers/init.go b/internal/web/actions/default/servers/groups/group/settings/headers/init.go new file mode 100644 index 00000000..9fc77b0f --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/headers/init.go @@ -0,0 +1,19 @@ +package headers + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" + "github.com/iwind/TeaGo" +) + +func init() { + TeaGo.BeforeStart(func(server *TeaGo.Server) { + server. + Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). + Data("teaMenu", "servers"). + Data("teaSubMenu", "group"). + Prefix("/servers/groups/group/settings/headers"). + GetPost("", new(IndexAction)). + EndAll() + }) +} diff --git a/internal/web/actions/default/servers/groups/group/settings/index/index.go b/internal/web/actions/default/servers/groups/group/settings/index/index.go index 770e2f94..0e0c9815 100644 --- a/internal/web/actions/default/servers/groups/group/settings/index/index.go +++ b/internal/web/actions/default/servers/groups/group/settings/index/index.go @@ -3,6 +3,7 @@ package reverseProxy import ( + teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/iwind/TeaGo/types" ) @@ -18,6 +19,10 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { GroupId int64 }) { - this.RedirectURL("/servers/groups/group/settings/httpReverseProxy?groupId=" + types.String(params.GroupId)) + if teaconst.IsPlus { + this.RedirectURL("/servers/groups/group/settings/web?groupId=" + types.String(params.GroupId)) + } else { + this.RedirectURL("/servers/groups/group/settings/httpReverseProxy?groupId=" + types.String(params.GroupId)) + } return } diff --git a/internal/web/actions/default/servers/groups/group/settings/remoteAddr/index.go b/internal/web/actions/default/servers/groups/group/settings/remoteAddr/index.go new file mode 100644 index 00000000..c55c2ad5 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/remoteAddr/index.go @@ -0,0 +1,68 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package remoteAddr + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "setting", "index") + this.SecondMenu("remoteAddr") +} + +func (this *IndexAction) RunGet(params struct { + GroupId int64 +}) { + _, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "remoteAddr") + if err != nil { + this.ErrorPage(err) + return + } + + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerGroupId(this.AdminContext(), params.GroupId) + if err != nil { + this.ErrorPage(err) + return + } + + this.Data["webId"] = webConfig.Id + this.Data["remoteAddrConfig"] = webConfig.RemoteAddr + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + WebId int64 + RemoteAddrJSON []byte + + Must *actions.Must + CSRF *actionutils.CSRF +}) { + var remoteAddrConfig = &serverconfigs.HTTPRemoteAddrConfig{} + err := json.Unmarshal(params.RemoteAddrJSON, remoteAddrConfig) + if err != nil { + this.Fail("参数校验失败:" + err.Error()) + } + + _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRemoteAddr(this.AdminContext(), &pb.UpdateHTTPWebRemoteAddrRequest{ + WebId: params.WebId, + RemoteAddrJSON: params.RemoteAddrJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/remoteAddr/init.go b/internal/web/actions/default/servers/groups/group/settings/remoteAddr/init.go new file mode 100644 index 00000000..5cfd9298 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/remoteAddr/init.go @@ -0,0 +1,19 @@ +package remoteAddr + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" + "github.com/iwind/TeaGo" +) + +func init() { + TeaGo.BeforeStart(func(server *TeaGo.Server) { + server. + Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). + Data("teaMenu", "servers"). + Data("teaSubMenu", "group"). + Prefix("/servers/groups/group/settings/remoteAddr"). + GetPost("", new(IndexAction)). + EndAll() + }) +} diff --git a/internal/web/actions/default/servers/groups/group/settings/stat/index.go b/internal/web/actions/default/servers/groups/group/settings/stat/index.go new file mode 100644 index 00000000..ed05847f --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/stat/index.go @@ -0,0 +1,60 @@ +package stat + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "setting", "index") + this.SecondMenu("stat") +} + +func (this *IndexAction) RunGet(params struct { + GroupId int64 +}) { + _, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "stat") + if err != nil { + this.ErrorPage(err) + return + } + + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerGroupId(this.AdminContext(), params.GroupId) + if err != nil { + this.ErrorPage(err) + return + } + + this.Data["webId"] = webConfig.Id + this.Data["statConfig"] = webConfig.StatRef + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + WebId int64 + StatJSON []byte + + Must *actions.Must +}) { + defer this.CreateLogInfo("修改Web %d 的统计设置", params.WebId) + + // TODO 校验配置 + + _, err := this.RPC().HTTPWebRPC().UpdateHTTPWebStat(this.AdminContext(), &pb.UpdateHTTPWebStatRequest{ + WebId: params.WebId, + StatJSON: params.StatJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/stat/init.go b/internal/web/actions/default/servers/groups/group/settings/stat/init.go new file mode 100644 index 00000000..d85a7d7c --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/stat/init.go @@ -0,0 +1,19 @@ +package stat + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" + "github.com/iwind/TeaGo" +) + +func init() { + TeaGo.BeforeStart(func(server *TeaGo.Server) { + server. + Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). + Data("teaMenu", "servers"). + Data("teaSubMenu", "group"). + Prefix("/servers/groups/group/settings/stat"). + GetPost("", new(IndexAction)). + EndAll() + }) +} diff --git a/internal/web/actions/default/servers/groups/group/settings/waf/group.go b/internal/web/actions/default/servers/groups/group/settings/waf/group.go new file mode 100644 index 00000000..9b58d071 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/waf/group.go @@ -0,0 +1,100 @@ +package waf + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" + "github.com/iwind/TeaGo/lists" + "github.com/iwind/TeaGo/maps" + "strings" +) + +type GroupAction struct { + actionutils.ParentAction +} + +func (this *GroupAction) Init() { + this.Nav("", "setting", this.ParamString("type")) + this.SecondMenu("waf") +} + +func (this *GroupAction) RunGet(params struct { + FirewallPolicyId int64 + GroupId int64 + Type string +}) { + this.Data["type"] = params.Type + this.Data["firewallPolicyId"] = params.FirewallPolicyId + + // policy + firewallPolicy, err := dao.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicyConfig(this.AdminContext(), params.FirewallPolicyId) + if err != nil { + this.ErrorPage(err) + return + } + if firewallPolicy == nil { + this.NotFound("firewallPolicy", params.FirewallPolicyId) + return + } + + // group config + groupConfig, err := dao.SharedHTTPFirewallRuleGroupDAO.FindRuleGroupConfig(this.AdminContext(), params.GroupId) + if err != nil { + this.ErrorPage(err) + return + } + if groupConfig == nil { + this.NotFound("firewallRuleGroup", params.GroupId) + return + } + + this.Data["group"] = groupConfig + + // rule sets + this.Data["sets"] = lists.Map(groupConfig.Sets, func(k int, v interface{}) interface{} { + set := v.(*firewallconfigs.HTTPFirewallRuleSet) + + var actionMaps = []maps.Map{} + for _, action := range set.Actions { + def := firewallconfigs.FindActionDefinition(action.Code) + if def == nil { + continue + } + + actionMaps = append(actionMaps, maps.Map{ + "code": strings.ToUpper(action.Code), + "name": def.Name, + "category": def.Category, + "options": action.Options, + }) + } + + return maps.Map{ + "id": set.Id, + "name": set.Name, + "rules": lists.Map(set.Rules, func(k int, v interface{}) interface{} { + rule := v.(*firewallconfigs.HTTPFirewallRule) + var errString = "" + var err = rule.Init() + if err != nil { + errString = err.Error() + } + return maps.Map{ + "param": rule.Param, + "paramFilters": rule.ParamFilters, + "operator": rule.Operator, + "value": rule.Value, + "isCaseInsensitive": rule.IsCaseInsensitive, + "isComposed": firewallconfigs.CheckCheckpointIsComposed(rule.Prefix()), + "checkpointOptions": rule.CheckpointOptions, + "err": errString, + } + }), + "isOn": set.IsOn, + "actions": actionMaps, + "connector": strings.ToUpper(set.Connector), + } + }) + + this.Show() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/waf/groups.go b/internal/web/actions/default/servers/groups/group/settings/waf/groups.go new file mode 100644 index 00000000..565ad5cf --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/waf/groups.go @@ -0,0 +1,83 @@ +package waf + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/iwind/TeaGo/maps" +) + +type GroupsAction struct { + actionutils.ParentAction +} + +func (this *GroupsAction) Init() { + this.Nav("", "setting", this.ParamString("type")) + this.SecondMenu("waf") +} + +func (this *GroupsAction) RunGet(params struct { + ServerId int64 + FirewallPolicyId int64 + Type string +}) { + this.Data["firewallPolicyId"] = params.FirewallPolicyId + this.Data["type"] = params.Type + + firewallPolicy, err := dao.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicyConfig(this.AdminContext(), params.FirewallPolicyId) + if err != nil { + this.ErrorPage(err) + return + } + if firewallPolicy == nil { + this.NotFound("firewallPolicy", params.FirewallPolicyId) + return + } + + groupMaps := []maps.Map{} + + // inbound + if params.Type == "inbound" { + if firewallPolicy.Inbound != nil { + for _, g := range firewallPolicy.Inbound.Groups { + groupMaps = append(groupMaps, maps.Map{ + "id": g.Id, + "name": g.Name, + "code": g.Code, + "isOn": g.IsOn, + "description": g.Description, + "countSets": len(g.Sets), + "canDelete": len(g.Code) == 0, + }) + } + } + } + + // outbound + if params.Type == "outbound" { + if firewallPolicy.Outbound != nil { + for _, g := range firewallPolicy.Outbound.Groups { + groupMaps = append(groupMaps, maps.Map{ + "id": g.Id, + "name": g.Name, + "code": g.Code, + "isOn": g.IsOn, + "description": g.Description, + "countSets": len(g.Sets), + "canDelete": len(g.Code) == 0, + }) + } + } + } + + this.Data["groups"] = groupMaps + + // WAF是否启用 + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["wafIsOn"] = webConfig.FirewallRef != nil && webConfig.FirewallRef.IsOn + + this.Show() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/waf/index.go b/internal/web/actions/default/servers/groups/group/settings/waf/index.go new file mode 100644 index 00000000..a5695c68 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/waf/index.go @@ -0,0 +1,76 @@ +package waf + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "setting", "index") + this.SecondMenu("waf") +} + +func (this *IndexAction) RunGet(params struct { + GroupId int64 +}) { + _, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "waf") + if err != nil { + this.ErrorPage(err) + return + } + + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerGroupId(this.AdminContext(), params.GroupId) + if err != nil { + this.ErrorPage(err) + return + } + + this.Data["webId"] = webConfig.Id + this.Data["firewallConfig"] = webConfig.FirewallRef + + // 获取当前服务所在集群的WAF设置 + this.Data["firewallPolicy"] = nil + + // 当前的Server独立设置 + if webConfig.FirewallRef == nil || webConfig.FirewallRef.FirewallPolicyId == 0 { + firewallPolicyId, err := dao.SharedHTTPWebDAO.InitEmptyHTTPFirewallPolicy(this.AdminContext(), params.GroupId, 0, webConfig.Id, webConfig.FirewallRef != nil && webConfig.FirewallRef.IsOn) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["firewallPolicyId"] = firewallPolicyId + } else { + this.Data["firewallPolicyId"] = webConfig.FirewallRef.FirewallPolicyId + } + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + WebId int64 + FirewallJSON []byte + + Must *actions.Must +}) { + defer this.CreateLogInfo("修改Web %d 的WAF设置", params.WebId) + + // TODO 检查配置 + + _, err := this.RPC().HTTPWebRPC().UpdateHTTPWebFirewall(this.AdminContext(), &pb.UpdateHTTPWebFirewallRequest{ + WebId: params.WebId, + FirewallJSON: params.FirewallJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/waf/init.go b/internal/web/actions/default/servers/groups/group/settings/waf/init.go new file mode 100644 index 00000000..feb474a0 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/waf/init.go @@ -0,0 +1,33 @@ +package waf + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/waf/ipadmin" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/serverutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" + "github.com/iwind/TeaGo" +) + +func init() { + TeaGo.BeforeStart(func(server *TeaGo.Server) { + server. + Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). + Helper(serverutils.NewServerHelper()). + Data("teaMenu", "servers"). + Data("teaSubMenu", "group"). + Prefix("/servers/groups/group/settings/waf"). + GetPost("", new(IndexAction)). + Get("/ipadmin/allowList", new(ipadmin.AllowListAction)). + Get("/ipadmin/denyList", new(ipadmin.DenyListAction)). + GetPost("/ipadmin/countries", new(ipadmin.CountriesAction)). + GetPost("/ipadmin/provinces", new(ipadmin.ProvincesAction)). + GetPost("/ipadmin/updateIPPopup", new(ipadmin.UpdateIPPopupAction)). + Post("/ipadmin/deleteIP", new(ipadmin.DeleteIPAction)). + GetPost("/ipadmin/test", new(ipadmin.TestAction)). + + // 规则相关 + Get("/groups", new(GroupsAction)). + Get("/group", new(GroupAction)). + EndAll() + }) +} diff --git a/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/allowList.go b/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/allowList.go new file mode 100644 index 00000000..0b831888 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/allowList.go @@ -0,0 +1,95 @@ +package ipadmin + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" + "github.com/iwind/TeaGo/maps" + timeutil "github.com/iwind/TeaGo/utils/time" + "time" +) + +type AllowListAction struct { + actionutils.ParentAction +} + +func (this *AllowListAction) Init() { + this.Nav("", "setting", "allowList") + this.SecondMenu("waf") +} + +func (this *AllowListAction) RunGet(params struct { + ServerId int64 + FirewallPolicyId int64 +}) { + this.Data["featureIsOn"] = true + this.Data["firewallPolicyId"] = params.FirewallPolicyId + + listId, err := dao.SharedIPListDAO.FindAllowIPListIdWithServerId(this.AdminContext(), params.ServerId) + if err != nil { + this.ErrorPage(err) + return + } + + // 创建 + if listId == 0 { + listId, err = dao.SharedIPListDAO.CreateIPListForServerId(this.AdminContext(), params.ServerId, "white") + if err != nil { + this.ErrorPage(err) + return + } + } + + this.Data["listId"] = listId + + // 数量 + countResp, err := this.RPC().IPItemRPC().CountIPItemsWithListId(this.AdminContext(), &pb.CountIPItemsWithListIdRequest{IpListId: listId}) + if err != nil { + this.ErrorPage(err) + return + } + count := countResp.Count + page := this.NewPage(count) + this.Data["page"] = page.AsHTML() + + // 列表 + itemsResp, err := this.RPC().IPItemRPC().ListIPItemsWithListId(this.AdminContext(), &pb.ListIPItemsWithListIdRequest{ + IpListId: listId, + Offset: page.Offset, + Size: page.Size, + }) + if err != nil { + this.ErrorPage(err) + return + } + itemMaps := []maps.Map{} + for _, item := range itemsResp.IpItems { + expiredTime := "" + if item.ExpiredAt > 0 { + expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt) + } + + itemMaps = append(itemMaps, maps.Map{ + "id": item.Id, + "ipFrom": item.IpFrom, + "ipTo": item.IpTo, + "expiredTime": expiredTime, + "reason": item.Reason, + "type": item.Type, + "isExpired": item.ExpiredAt > 0 && item.ExpiredAt < time.Now().Unix(), + "eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel), + }) + } + this.Data["items"] = itemMaps + + // WAF是否启用 + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["wafIsOn"] = webConfig.FirewallRef != nil && webConfig.FirewallRef.IsOn + + this.Show() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/countries.go b/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/countries.go new file mode 100644 index 00000000..4bc68e7b --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/countries.go @@ -0,0 +1,121 @@ +package ipadmin + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" + "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/lists" + "github.com/iwind/TeaGo/maps" + "strings" +) + +type CountriesAction struct { + actionutils.ParentAction +} + +func (this *CountriesAction) Init() { + this.Nav("", "setting", "country") + this.SecondMenu("waf") +} + +func (this *CountriesAction) RunGet(params struct { + FirewallPolicyId int64 + ServerId int64 +}) { + this.Data["featureIsOn"] = true + this.Data["firewallPolicyId"] = params.FirewallPolicyId + + this.Data["subMenuItem"] = "region" + + // 当前选中的地区 + policyConfig, err := dao.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicyConfig(this.AdminContext(), params.FirewallPolicyId) + if err != nil { + this.ErrorPage(err) + return + } + if policyConfig == nil { + this.NotFound("firewallPolicy", params.FirewallPolicyId) + return + } + selectedCountryIds := []int64{} + if policyConfig.Inbound != nil && policyConfig.Inbound.Region != nil { + selectedCountryIds = policyConfig.Inbound.Region.DenyCountryIds + } + + countriesResp, err := this.RPC().RegionCountryRPC().FindAllEnabledRegionCountries(this.AdminContext(), &pb.FindAllEnabledRegionCountriesRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + countryMaps := []maps.Map{} + for _, country := range countriesResp.Countries { + countryMaps = append(countryMaps, maps.Map{ + "id": country.Id, + "name": country.Name, + "letter": strings.ToUpper(string(country.Pinyin[0][0])), + "isChecked": lists.ContainsInt64(selectedCountryIds, country.Id), + }) + } + this.Data["countries"] = countryMaps + + // WAF是否启用 + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["wafIsOn"] = webConfig.FirewallRef != nil && webConfig.FirewallRef.IsOn + + this.Show() +} + +func (this *CountriesAction) RunPost(params struct { + FirewallPolicyId int64 + CountryIds []int64 + + Must *actions.Must +}) { + // 日志 + defer this.CreateLog(oplogs.LevelInfo, "WAF策略 %d 设置禁止访问的国家和地区", params.FirewallPolicyId) + + policyConfig, err := dao.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicyConfig(this.AdminContext(), params.FirewallPolicyId) + if err != nil { + this.ErrorPage(err) + return + } + if policyConfig == nil { + this.NotFound("firewallPolicy", params.FirewallPolicyId) + return + } + + if policyConfig.Inbound == nil { + policyConfig.Inbound = &firewallconfigs.HTTPFirewallInboundConfig{IsOn: true} + } + if policyConfig.Inbound.Region == nil { + policyConfig.Inbound.Region = &firewallconfigs.HTTPFirewallRegionConfig{ + IsOn: true, + } + } + policyConfig.Inbound.Region.DenyCountryIds = params.CountryIds + + inboundJSON, err := json.Marshal(policyConfig.Inbound) + if err != nil { + this.ErrorPage(err) + return + } + + _, err = this.RPC().HTTPFirewallPolicyRPC().UpdateHTTPFirewallInboundConfig(this.AdminContext(), &pb.UpdateHTTPFirewallInboundConfigRequest{ + HttpFirewallPolicyId: params.FirewallPolicyId, + InboundJSON: inboundJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/deleteIP.go b/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/deleteIP.go new file mode 100644 index 00000000..a5cf1dc2 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/deleteIP.go @@ -0,0 +1,29 @@ +package ipadmin + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" +) + +type DeleteIPAction struct { + actionutils.ParentAction +} + +func (this *DeleteIPAction) RunPost(params struct { + FirewallPolicyId int64 + ItemId int64 +}) { + // 日志 + defer this.CreateLog(oplogs.LevelInfo, "从WAF策略 %d 名单中删除IP %d", params.FirewallPolicyId, params.ItemId) + + // TODO 判断权限 + + _, err := this.RPC().IPItemRPC().DeleteIPItem(this.AdminContext(), &pb.DeleteIPItemRequest{IpItemId: params.ItemId}) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/denyList.go b/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/denyList.go new file mode 100644 index 00000000..5813acfc --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/denyList.go @@ -0,0 +1,95 @@ +package ipadmin + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" + "github.com/iwind/TeaGo/maps" + timeutil "github.com/iwind/TeaGo/utils/time" + "time" +) + +type DenyListAction struct { + actionutils.ParentAction +} + +func (this *DenyListAction) Init() { + this.Nav("", "setting", "denyList") + this.SecondMenu("waf") +} + +func (this *DenyListAction) RunGet(params struct { + FirewallPolicyId int64 + ServerId int64 +}) { + this.Data["featureIsOn"] = true + this.Data["firewallPolicyId"] = params.FirewallPolicyId + + listId, err := dao.SharedIPListDAO.FindDenyIPListIdWithServerId(this.AdminContext(), params.ServerId) + if err != nil { + this.ErrorPage(err) + return + } + + // 创建 + if listId == 0 { + listId, err = dao.SharedIPListDAO.CreateIPListForServerId(this.AdminContext(), params.ServerId, "black") + if err != nil { + this.ErrorPage(err) + return + } + } + + this.Data["listId"] = listId + + // 数量 + countResp, err := this.RPC().IPItemRPC().CountIPItemsWithListId(this.AdminContext(), &pb.CountIPItemsWithListIdRequest{IpListId: listId}) + if err != nil { + this.ErrorPage(err) + return + } + count := countResp.Count + page := this.NewPage(count) + this.Data["page"] = page.AsHTML() + + // 列表 + itemsResp, err := this.RPC().IPItemRPC().ListIPItemsWithListId(this.AdminContext(), &pb.ListIPItemsWithListIdRequest{ + IpListId: listId, + Offset: page.Offset, + Size: page.Size, + }) + if err != nil { + this.ErrorPage(err) + return + } + itemMaps := []maps.Map{} + for _, item := range itemsResp.IpItems { + expiredTime := "" + if item.ExpiredAt > 0 { + expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt) + } + + itemMaps = append(itemMaps, maps.Map{ + "id": item.Id, + "ipFrom": item.IpFrom, + "ipTo": item.IpTo, + "expiredTime": expiredTime, + "reason": item.Reason, + "type": item.Type, + "isExpired": item.ExpiredAt > 0 && item.ExpiredAt < time.Now().Unix(), + "eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel), + }) + } + this.Data["items"] = itemMaps + + // WAF是否启用 + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["wafIsOn"] = webConfig.FirewallRef != nil && webConfig.FirewallRef.IsOn + + this.Show() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/provinces.go b/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/provinces.go new file mode 100644 index 00000000..3b92ffe4 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/provinces.go @@ -0,0 +1,122 @@ +package ipadmin + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" + "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/lists" + "github.com/iwind/TeaGo/maps" +) + +const ChinaCountryId = 1 + +type ProvincesAction struct { + actionutils.ParentAction +} + +func (this *ProvincesAction) Init() { + this.Nav("", "setting", "province") + this.SecondMenu("waf") +} + +func (this *ProvincesAction) RunGet(params struct { + FirewallPolicyId int64 + ServerId int64 +}) { + this.Data["featureIsOn"] = true + this.Data["firewallPolicyId"] = params.FirewallPolicyId + this.Data["subMenuItem"] = "province" + + // 当前选中的省份 + policyConfig, err := dao.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicyConfig(this.AdminContext(), params.FirewallPolicyId) + if err != nil { + this.ErrorPage(err) + return + } + if policyConfig == nil { + this.NotFound("firewallPolicy", params.FirewallPolicyId) + return + } + selectedProvinceIds := []int64{} + if policyConfig.Inbound != nil && policyConfig.Inbound.Region != nil { + selectedProvinceIds = policyConfig.Inbound.Region.DenyProvinceIds + } + + provincesResp, err := this.RPC().RegionProvinceRPC().FindAllEnabledRegionProvincesWithCountryId(this.AdminContext(), &pb.FindAllEnabledRegionProvincesWithCountryIdRequest{ + CountryId: int64(ChinaCountryId), + }) + if err != nil { + this.ErrorPage(err) + return + } + provinceMaps := []maps.Map{} + for _, province := range provincesResp.Provinces { + provinceMaps = append(provinceMaps, maps.Map{ + "id": province.Id, + "name": province.Name, + "isChecked": lists.ContainsInt64(selectedProvinceIds, province.Id), + }) + } + this.Data["provinces"] = provinceMaps + + // WAF是否启用 + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["wafIsOn"] = webConfig.FirewallRef != nil && webConfig.FirewallRef.IsOn + + this.Show() +} + +func (this *ProvincesAction) RunPost(params struct { + FirewallPolicyId int64 + ProvinceIds []int64 + + Must *actions.Must +}) { + // 日志 + defer this.CreateLog(oplogs.LevelInfo, "WAF策略 %d 设置禁止访问的省份", params.FirewallPolicyId) + + policyConfig, err := dao.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicyConfig(this.AdminContext(), params.FirewallPolicyId) + if err != nil { + this.ErrorPage(err) + return + } + if policyConfig == nil { + this.NotFound("firewallPolicy", params.FirewallPolicyId) + return + } + + if policyConfig.Inbound == nil { + policyConfig.Inbound = &firewallconfigs.HTTPFirewallInboundConfig{IsOn: true} + } + if policyConfig.Inbound.Region == nil { + policyConfig.Inbound.Region = &firewallconfigs.HTTPFirewallRegionConfig{ + IsOn: true, + } + } + policyConfig.Inbound.Region.DenyProvinceIds = params.ProvinceIds + + inboundJSON, err := json.Marshal(policyConfig.Inbound) + if err != nil { + this.ErrorPage(err) + return + } + + _, err = this.RPC().HTTPFirewallPolicyRPC().UpdateHTTPFirewallInboundConfig(this.AdminContext(), &pb.UpdateHTTPFirewallInboundConfigRequest{ + HttpFirewallPolicyId: params.FirewallPolicyId, + InboundJSON: inboundJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/test.go b/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/test.go new file mode 100644 index 00000000..29cac308 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/test.go @@ -0,0 +1,100 @@ +package ipadmin + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" + "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/maps" + timeutil "github.com/iwind/TeaGo/utils/time" +) + +type TestAction struct { + actionutils.ParentAction +} + +func (this *TestAction) Init() { + this.Nav("", "setting", "test") + this.SecondMenu("waf") +} + +func (this *TestAction) RunGet(params struct { + ServerId int64 + FirewallPolicyId int64 +}) { + this.Data["featureIsOn"] = true + this.Data["firewallPolicyId"] = params.FirewallPolicyId + this.Data["subMenuItem"] = "province" + + // WAF是否启用 + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["wafIsOn"] = webConfig.FirewallRef != nil && webConfig.FirewallRef.IsOn + + this.Show() +} + +func (this *TestAction) RunPost(params struct { + FirewallPolicyId int64 + Ip string + + Must *actions.Must +}) { + resp, err := this.RPC().HTTPFirewallPolicyRPC().CheckHTTPFirewallPolicyIPStatus(this.AdminContext(), &pb.CheckHTTPFirewallPolicyIPStatusRequest{ + HttpFirewallPolicyId: params.FirewallPolicyId, + Ip: params.Ip, + }) + if err != nil { + this.ErrorPage(err) + return + } + + resultMap := maps.Map{ + "isDone": true, + "isFound": resp.IsFound, + "isOk": resp.IsOk, + "error": resp.Error, + "isAllowed": resp.IsAllowed, + } + + if resp.IpList != nil { + resultMap["list"] = maps.Map{ + "id": resp.IpList.Id, + "name": resp.IpList.Name, + } + } + if resp.IpItem != nil { + resultMap["item"] = maps.Map{ + "id": resp.IpItem.Id, + "ipFrom": resp.IpItem.IpFrom, + "ipTo": resp.IpItem.IpTo, + "reason": resp.IpItem.Reason, + "expiredAt": resp.IpItem.ExpiredAt, + "expiredTime": timeutil.FormatTime("Y-m-d H:i:s", resp.IpItem.ExpiredAt), + "type": resp.IpItem.Type, + "eventLevelName": firewallconfigs.FindFirewallEventLevelName(resp.IpItem.EventLevel), + } + } + + if resp.RegionCountry != nil { + resultMap["country"] = maps.Map{ + "id": resp.RegionCountry.Id, + "name": resp.RegionCountry.Name, + } + } + + if resp.RegionProvince != nil { + resultMap["province"] = maps.Map{ + "id": resp.RegionProvince.Id, + "name": resp.RegionProvince.Name, + } + } + + this.Data["result"] = resultMap + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/updateIPPopup.go b/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/updateIPPopup.go new file mode 100644 index 00000000..b703d13e --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/waf/ipadmin/updateIPPopup.go @@ -0,0 +1,117 @@ +package ipadmin + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" + "github.com/TeaOSLab/EdgeAdmin/internal/utils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/maps" +) + +type UpdateIPPopupAction struct { + actionutils.ParentAction +} + +func (this *UpdateIPPopupAction) Init() { + this.Nav("", "", "") +} + +func (this *UpdateIPPopupAction) RunGet(params struct { + ItemId int64 +}) { + itemResp, err := this.RPC().IPItemRPC().FindEnabledIPItem(this.AdminContext(), &pb.FindEnabledIPItemRequest{IpItemId: params.ItemId}) + if err != nil { + this.ErrorPage(err) + return + } + item := itemResp.IpItem + if item == nil { + this.NotFound("ipItem", params.ItemId) + return + } + + this.Data["item"] = maps.Map{ + "id": item.Id, + "ipFrom": item.IpFrom, + "ipTo": item.IpTo, + "expiredAt": item.ExpiredAt, + "reason": item.Reason, + "type": item.Type, + "eventLevel": item.EventLevel, + } + + this.Data["type"] = item.Type + + this.Show() +} + +func (this *UpdateIPPopupAction) RunPost(params struct { + ItemId int64 + + IpFrom string + IpTo string + ExpiredAt int64 + Reason string + Type string + EventLevel string + + Must *actions.Must + CSRF *actionutils.CSRF +}) { + // 日志 + defer this.CreateLog(oplogs.LevelInfo, "修改WAF策略名单中的IP %d", params.ItemId) + + // TODO 校验ItemId所属用户 + + switch params.Type { + case "ipv4": + params.Must. + Field("ipFrom", params.IpFrom). + Require("请输入开始IP") + + // 校验IP格式(ipFrom/ipTo) + var ipFromLong uint64 + if !utils.IsIPv4(params.IpFrom) { + this.Fail("请输入正确的开始IP") + } + ipFromLong = utils.IP2Long(params.IpFrom) + + var ipToLong uint64 + if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) { + ipToLong = utils.IP2Long(params.IpTo) + this.Fail("请输入正确的结束IP") + } + + if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong { + params.IpTo, params.IpFrom = params.IpFrom, params.IpTo + } + case "ipv6": + params.Must. + Field("ipFrom", params.IpFrom). + Require("请输入IP") + + // 校验IP格式(ipFrom) + if !utils.IsIPv6(params.IpFrom) { + this.Fail("请输入正确的IPv6地址") + } + case "all": + params.IpFrom = "0.0.0.0" + } + + _, err := this.RPC().IPItemRPC().UpdateIPItem(this.AdminContext(), &pb.UpdateIPItemRequest{ + IpItemId: params.ItemId, + IpFrom: params.IpFrom, + IpTo: params.IpTo, + ExpiredAt: params.ExpiredAt, + Reason: params.Reason, + Type: params.Type, + EventLevel: params.EventLevel, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/web/index.go b/internal/web/actions/default/servers/groups/group/settings/web/index.go new file mode 100644 index 00000000..33a03f65 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/web/index.go @@ -0,0 +1,59 @@ +package web + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "setting", "index") + this.SecondMenu("web") +} + +func (this *IndexAction) RunGet(params struct { + GroupId int64 +}) { + _, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "web") + if err != nil { + this.ErrorPage(err) + return + } + + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerGroupId(this.AdminContext(), params.GroupId) + if err != nil { + this.ErrorPage(err) + return + } + + this.Data["webId"] = webConfig.Id + this.Data["rootConfig"] = webConfig.Root + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + WebId int64 + RootJSON []byte + + Must *actions.Must +}) { + defer this.CreateLogInfo("修改Web %d 的首页文件名", params.WebId) + + _, err := this.RPC().HTTPWebRPC().UpdateHTTPWeb(this.AdminContext(), &pb.UpdateHTTPWebRequest{ + WebId: params.WebId, + RootJSON: params.RootJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/web/init.go b/internal/web/actions/default/servers/groups/group/settings/web/init.go new file mode 100644 index 00000000..ae4ebb68 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/web/init.go @@ -0,0 +1,19 @@ +package web + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" + "github.com/iwind/TeaGo" +) + +func init() { + TeaGo.BeforeStart(func(server *TeaGo.Server) { + server. + Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). + Data("teaMenu", "servers"). + Data("teaSubMenu", "group"). + Prefix("/servers/groups/group/settings/web"). + GetPost("", new(IndexAction)). + EndAll() + }) +} diff --git a/internal/web/actions/default/servers/groups/group/settings/webp/index.go b/internal/web/actions/default/servers/groups/group/settings/webp/index.go new file mode 100644 index 00000000..a86b63dd --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/webp/index.go @@ -0,0 +1,68 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package webp + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "setting", "index") + this.SecondMenu("webp") +} + +func (this *IndexAction) RunGet(params struct { + GroupId int64 +}) { + _, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "webp") + if err != nil { + this.ErrorPage(err) + return + } + + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerGroupId(this.AdminContext(), params.GroupId) + if err != nil { + this.ErrorPage(err) + return + } + + this.Data["webId"] = webConfig.Id + this.Data["webpConfig"] = webConfig.WebP + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + WebId int64 + WebpJSON []byte + + Must *actions.Must + CSRF *actionutils.CSRF +}) { + var webpConfig = &serverconfigs.WebPImageConfig{} + err := json.Unmarshal(params.WebpJSON, webpConfig) + if err != nil { + this.Fail("参数校验失败:" + err.Error()) + } + + _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebWebP(this.AdminContext(), &pb.UpdateHTTPWebWebPRequest{ + WebId: params.WebId, + WebpJSON: params.WebpJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/webp/init.go b/internal/web/actions/default/servers/groups/group/settings/webp/init.go new file mode 100644 index 00000000..5be0e493 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/webp/init.go @@ -0,0 +1,19 @@ +package webp + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" + "github.com/iwind/TeaGo" +) + +func init() { + TeaGo.BeforeStart(func(server *TeaGo.Server) { + server. + Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). + Data("teaMenu", "servers"). + Data("teaSubMenu", "group"). + Prefix("/servers/groups/group/settings/webp"). + GetPost("", new(IndexAction)). + EndAll() + }) +} diff --git a/internal/web/actions/default/servers/groups/group/settings/websocket/index.go b/internal/web/actions/default/servers/groups/group/settings/websocket/index.go new file mode 100644 index 00000000..1baf1d62 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/websocket/index.go @@ -0,0 +1,122 @@ +package websocket + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "setting", "index") + this.SecondMenu("websocket") +} + +func (this *IndexAction) RunGet(params struct { + GroupId int64 +}) { + _, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "websocket") + if err != nil { + this.ErrorPage(err) + return + } + + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerGroupId(this.AdminContext(), params.GroupId) + if err != nil { + this.ErrorPage(err) + return + } + + this.Data["webId"] = webConfig.Id + this.Data["websocketRef"] = webConfig.WebsocketRef + this.Data["websocketConfig"] = webConfig.Websocket + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + WebId int64 + WebsocketRefJSON []byte + WebsocketJSON []byte + + Must *actions.Must +}) { + defer this.CreateLogInfo("修改Web %d 的Websocket设置", params.WebId) + + // TODO 检查配置 + + websocketRef := &serverconfigs.HTTPWebsocketRef{} + err := json.Unmarshal(params.WebsocketRefJSON, websocketRef) + if err != nil { + this.ErrorPage(err) + return + } + + websocketConfig := &serverconfigs.HTTPWebsocketConfig{} + err = json.Unmarshal(params.WebsocketJSON, websocketConfig) + if err != nil { + this.ErrorPage(err) + return + } + err = websocketConfig.Init() + if err != nil { + this.ErrorPage(err) + return + } + + // 创建 + handshakeTimeoutJSON, err := json.Marshal(websocketConfig.HandshakeTimeout) + if err != nil { + this.ErrorPage(err) + return + } + + // 创建或修改 + if websocketConfig.Id <= 0 { + createResp, err := this.RPC().HTTPWebsocketRPC().CreateHTTPWebsocket(this.AdminContext(), &pb.CreateHTTPWebsocketRequest{ + HandshakeTimeoutJSON: handshakeTimeoutJSON, + AllowAllOrigins: websocketConfig.AllowAllOrigins, + AllowedOrigins: websocketConfig.AllowedOrigins, + RequestSameOrigin: websocketConfig.RequestSameOrigin, + RequestOrigin: websocketConfig.RequestOrigin, + }) + if err != nil { + this.ErrorPage(err) + return + } + websocketConfig.Id = createResp.WebsocketId + } else { + _, err = this.RPC().HTTPWebsocketRPC().UpdateHTTPWebsocket(this.AdminContext(), &pb.UpdateHTTPWebsocketRequest{ + WebsocketId: websocketConfig.Id, + HandshakeTimeoutJSON: handshakeTimeoutJSON, + AllowAllOrigins: websocketConfig.AllowAllOrigins, + AllowedOrigins: websocketConfig.AllowedOrigins, + RequestSameOrigin: websocketConfig.RequestSameOrigin, + RequestOrigin: websocketConfig.RequestOrigin, + }) + } + + websocketRef.WebsocketId = websocketConfig.Id + websocketRefJSON, err := json.Marshal(websocketRef) + if err != nil { + this.ErrorPage(err) + return + } + _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebWebsocket(this.AdminContext(), &pb.UpdateHTTPWebWebsocketRequest{ + WebId: params.WebId, + WebsocketJSON: websocketRefJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/websocket/init.go b/internal/web/actions/default/servers/groups/group/settings/websocket/init.go new file mode 100644 index 00000000..f5538ecf --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/websocket/init.go @@ -0,0 +1,19 @@ +package websocket + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" + "github.com/iwind/TeaGo" +) + +func init() { + TeaGo.BeforeStart(func(server *TeaGo.Server) { + server. + Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). + Data("teaMenu", "servers"). + Data("teaSubMenu", "group"). + Prefix("/servers/groups/group/settings/websocket"). + GetPost("", new(IndexAction)). + EndAll() + }) +} diff --git a/internal/web/actions/default/servers/server/settings/accessLog/index.go b/internal/web/actions/default/servers/server/settings/accessLog/index.go index 1764c671..50ece6f0 100644 --- a/internal/web/actions/default/servers/server/settings/accessLog/index.go +++ b/internal/web/actions/default/servers/server/settings/accessLog/index.go @@ -7,6 +7,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/types" ) type IndexAction struct { @@ -21,6 +22,17 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ServerId int64 }) { + // 服务分组设置 + groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ + ServerId: params.ServerId, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["hasGroupConfig"] = groupResp.HasAccessLogConfig + this.Data["groupSettingURL"] = "/servers/groups/group/settings/accessLog?groupId=" + types.String(groupResp.ServerGroupId) + // 获取配置 webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) if err != nil { diff --git a/internal/web/actions/default/servers/server/settings/cache/index.go b/internal/web/actions/default/servers/server/settings/cache/index.go index caf4bb28..a74523f0 100644 --- a/internal/web/actions/default/servers/server/settings/cache/index.go +++ b/internal/web/actions/default/servers/server/settings/cache/index.go @@ -9,6 +9,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" + "github.com/iwind/TeaGo/types" ) type IndexAction struct { @@ -23,6 +24,17 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ServerId int64 }) { + // 服务分组设置 + groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ + ServerId: params.ServerId, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["hasGroupConfig"] = groupResp.HasCacheConfig + this.Data["groupSettingURL"] = "/servers/groups/group/settings/cache?groupId=" + types.String(groupResp.ServerGroupId) + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/server/settings/charset/index.go b/internal/web/actions/default/servers/server/settings/charset/index.go index 110692bc..4adf0771 100644 --- a/internal/web/actions/default/servers/server/settings/charset/index.go +++ b/internal/web/actions/default/servers/server/settings/charset/index.go @@ -7,6 +7,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/types" ) type IndexAction struct { @@ -21,6 +22,17 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ServerId int64 }) { + // 服务分组设置 + groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ + ServerId: params.ServerId, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["hasGroupConfig"] = groupResp.HasCharsetConfig + this.Data["groupSettingURL"] = "/servers/groups/group/settings/charset?groupId=" + types.String(groupResp.ServerGroupId) + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/server/settings/compression/index.go b/internal/web/actions/default/servers/server/settings/compression/index.go index 1319e4fe..7876f638 100644 --- a/internal/web/actions/default/servers/server/settings/compression/index.go +++ b/internal/web/actions/default/servers/server/settings/compression/index.go @@ -9,6 +9,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/types" ) type IndexAction struct { @@ -23,6 +24,17 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ServerId int64 }) { + // 服务分组设置 + groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ + ServerId: params.ServerId, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["hasGroupConfig"] = groupResp.HasCompressionConfig + this.Data["groupSettingURL"] = "/servers/groups/group/settings/compression?groupId=" + types.String(groupResp.ServerGroupId) + // WebId webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) if err != nil { diff --git a/internal/web/actions/default/servers/server/settings/headers/createSetPopup.go b/internal/web/actions/default/servers/server/settings/headers/createSetPopup.go index ad1fae37..ef40837b 100644 --- a/internal/web/actions/default/servers/server/settings/headers/createSetPopup.go +++ b/internal/web/actions/default/servers/server/settings/headers/createSetPopup.go @@ -18,7 +18,6 @@ func (this *CreateSetPopupAction) Init() { } func (this *CreateSetPopupAction) RunGet(params struct { - ServerId int64 HeaderPolicyId int64 }) { this.Data["headerPolicyId"] = params.HeaderPolicyId diff --git a/internal/web/actions/default/servers/server/settings/headers/index.go b/internal/web/actions/default/servers/server/settings/headers/index.go index b80df2e2..58844cc6 100644 --- a/internal/web/actions/default/servers/server/settings/headers/index.go +++ b/internal/web/actions/default/servers/server/settings/headers/index.go @@ -6,6 +6,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" + "github.com/iwind/TeaGo/types" ) type IndexAction struct { @@ -20,6 +21,18 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ServerId int64 }) { + // 服务分组设置 + groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ + ServerId: params.ServerId, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["hasGroupRequestConfig"] = groupResp.HasRequestHeadersConfig + this.Data["hasGroupResponseConfig"] = groupResp.HasResponseHeadersConfig + this.Data["groupSettingURL"] = "/servers/groups/group/settings/headers?groupId=" + types.String(groupResp.ServerGroupId) + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/server/settings/remoteAddr/index.go b/internal/web/actions/default/servers/server/settings/remoteAddr/index.go index 85b4ce90..75312e11 100644 --- a/internal/web/actions/default/servers/server/settings/remoteAddr/index.go +++ b/internal/web/actions/default/servers/server/settings/remoteAddr/index.go @@ -9,6 +9,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/types" ) type IndexAction struct { @@ -23,6 +24,17 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ServerId int64 }) { + // 服务分组设置 + groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ + ServerId: params.ServerId, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["hasGroupConfig"] = groupResp.HasRemoteAddrConfig + this.Data["groupSettingURL"] = "/servers/groups/group/settings/remoteAddr?groupId=" + types.String(groupResp.ServerGroupId) + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/server/settings/stat/index.go b/internal/web/actions/default/servers/server/settings/stat/index.go index 9eeae21b..fdb4dd2e 100644 --- a/internal/web/actions/default/servers/server/settings/stat/index.go +++ b/internal/web/actions/default/servers/server/settings/stat/index.go @@ -5,6 +5,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/types" ) type IndexAction struct { @@ -19,6 +20,17 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ServerId int64 }) { + // 服务分组设置 + groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ + ServerId: params.ServerId, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["hasGroupConfig"] = groupResp.HasStatConfig + this.Data["groupSettingURL"] = "/servers/groups/group/settings/stat?groupId=" + types.String(groupResp.ServerGroupId) + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/server/settings/waf/index.go b/internal/web/actions/default/servers/server/settings/waf/index.go index 5bc09844..d5190549 100644 --- a/internal/web/actions/default/servers/server/settings/waf/index.go +++ b/internal/web/actions/default/servers/server/settings/waf/index.go @@ -7,6 +7,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" + "github.com/iwind/TeaGo/types" ) type IndexAction struct { @@ -21,6 +22,17 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ServerId int64 }) { + // 服务分组设置 + groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ + ServerId: params.ServerId, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["hasGroupConfig"] = groupResp.HasWAFConfig + this.Data["groupSettingURL"] = "/servers/groups/group/settings/waf?groupId=" + types.String(groupResp.ServerGroupId) + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) if err != nil { this.ErrorPage(err) @@ -50,7 +62,7 @@ func (this *IndexAction) RunGet(params struct { // 当前的Server独立设置 if webConfig.FirewallRef == nil || webConfig.FirewallRef.FirewallPolicyId == 0 { - firewallPolicyId, err := dao.SharedHTTPWebDAO.InitEmptyHTTPFirewallPolicy(this.AdminContext(), params.ServerId, webConfig.Id, webConfig.FirewallRef != nil && webConfig.FirewallRef.IsOn) + firewallPolicyId, err := dao.SharedHTTPWebDAO.InitEmptyHTTPFirewallPolicy(this.AdminContext(), 0, params.ServerId, webConfig.Id, webConfig.FirewallRef != nil && webConfig.FirewallRef.IsOn) if err != nil { this.ErrorPage(err) return diff --git a/internal/web/actions/default/servers/server/settings/web/index.go b/internal/web/actions/default/servers/server/settings/web/index.go index f144bd1e..1298d85e 100644 --- a/internal/web/actions/default/servers/server/settings/web/index.go +++ b/internal/web/actions/default/servers/server/settings/web/index.go @@ -5,6 +5,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/types" ) type IndexAction struct { @@ -19,6 +20,17 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ServerId int64 }) { + // 分组设置 + groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ + ServerId: params.ServerId, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["hasGroupConfig"] = groupResp.HasRootConfig + this.Data["groupSettingURL"] = "/servers/groups/group/settings/web?groupId=" + types.String(groupResp.ServerGroupId) + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/server/settings/webp/index.go b/internal/web/actions/default/servers/server/settings/webp/index.go index 1abe0541..0ff9a89d 100644 --- a/internal/web/actions/default/servers/server/settings/webp/index.go +++ b/internal/web/actions/default/servers/server/settings/webp/index.go @@ -9,6 +9,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/types" ) type IndexAction struct { @@ -23,6 +24,17 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ServerId int64 }) { + // 服务分组设置 + groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ + ServerId: params.ServerId, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["hasGroupConfig"] = groupResp.HasWebPConfig + this.Data["groupSettingURL"] = "/servers/groups/group/settings/webp?groupId=" + types.String(groupResp.ServerGroupId) + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/server/settings/websocket/index.go b/internal/web/actions/default/servers/server/settings/websocket/index.go index 7853f91a..08e05e41 100644 --- a/internal/web/actions/default/servers/server/settings/websocket/index.go +++ b/internal/web/actions/default/servers/server/settings/websocket/index.go @@ -7,6 +7,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/types" ) type IndexAction struct { @@ -21,6 +22,17 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ServerId int64 }) { + // 服务分组设置 + groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ + ServerId: params.ServerId, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["hasGroupConfig"] = groupResp.HasWebsocketConfig + this.Data["groupSettingURL"] = "/servers/groups/group/settings/websocket?groupId=" + types.String(groupResp.ServerGroupId) + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) if err != nil { this.ErrorPage(err) diff --git a/web/public/js/components/server/http-access-log-config-box.js b/web/public/js/components/server/http-access-log-config-box.js index 0edefde7..02189c8f 100644 --- a/web/public/js/components/server/http-access-log-config-box.js +++ b/web/public/js/components/server/http-access-log-config-box.js @@ -1,5 +1,5 @@ Vue.component("http-access-log-config-box", { - props: ["v-access-log-config", "v-fields", "v-default-field-codes", "v-is-location"], + props: ["v-access-log-config", "v-fields", "v-default-field-codes", "v-is-location", "v-is-group"], data: function () { let that = this @@ -47,9 +47,9 @@ Vue.component("http-access-log-config-box", { }, template: `
- - - +
+ + - +
是否开启访问日志存储 @@ -61,7 +61,7 @@ Vue.component("http-access-log-config-box", {
要存储的访问日志字段 @@ -99,7 +99,7 @@ Vue.component("http-access-log-config-box", {
-
+

WAF相关

diff --git a/web/public/js/components/server/http-cache-config-box.js b/web/public/js/components/server/http-cache-config-box.js index 1db206b9..c47a5e23 100644 --- a/web/public/js/components/server/http-cache-config-box.js +++ b/web/public/js/components/server/http-cache-config-box.js @@ -1,5 +1,5 @@ Vue.component("http-cache-config-box", { - props: ["v-cache-config", "v-is-location", "v-cache-policy"], + props: ["v-cache-config", "v-is-location", "v-is-group", "v-cache-policy"], data: function () { let cacheConfig = this.vCacheConfig if (cacheConfig == null) { @@ -16,15 +16,15 @@ Vue.component("http-cache-config-box", { }, methods: { isOn: function () { - return (!this.vIsLocation || this.cacheConfig.isPrior) && this.cacheConfig.isOn + return ((!this.vIsLocation && !this.vIsGroup) || this.cacheConfig.isPrior) && this.cacheConfig.isOn } }, template: `
- - - + + +
缓存策略
{{vCachePolicy.name}} diff --git a/web/public/js/components/server/http-charsets-box.js b/web/public/js/components/server/http-charsets-box.js index 34e7e87c..088fcf4c 100644 --- a/web/public/js/components/server/http-charsets-box.js +++ b/web/public/js/components/server/http-charsets-box.js @@ -1,5 +1,5 @@ Vue.component("http-charsets-box", { - props: ["v-usual-charsets", "v-all-charsets", "v-charset-config", "v-is-location"], + props: ["v-usual-charsets", "v-all-charsets", "v-charset-config", "v-is-location", "v-is-group"], data: function () { let charsetConfig = this.vCharsetConfig if (charsetConfig == null) { @@ -23,8 +23,8 @@ Vue.component("http-charsets-box", { template: `
- - + + - + - - + +
是否启用 @@ -35,7 +35,7 @@ Vue.component("http-charsets-box", {
选择字符编码
字符编码是否大写 diff --git a/web/public/js/components/server/http-compression-config-box.js b/web/public/js/components/server/http-compression-config-box.js index 7b8ff836..3acb91d4 100644 --- a/web/public/js/components/server/http-compression-config-box.js +++ b/web/public/js/components/server/http-compression-config-box.js @@ -1,6 +1,6 @@ // 压缩配置 Vue.component("http-compression-config-box", { - props: ["v-compression-config", "v-is-location"], + props: ["v-compression-config", "v-is-location", "v-is-group"], mounted: function () { let that = this sortLoad(function () { @@ -92,7 +92,7 @@ Vue.component("http-compression-config-box", { }, methods: { isOn: function () { - return (!this.vIsLocation || this.config.isPrior) && this.config.isOn + return ((!this.vIsLocation && !this.vIsGroup) || this.config.isPrior) && this.config.isOn }, changeExtensions: function (values) { values.forEach(function (v, k) { @@ -144,8 +144,8 @@ Vue.component("http-compression-config-box", { template: `
- - + +
是否启用 diff --git a/web/public/js/components/server/http-firewall-config-box.js b/web/public/js/components/server/http-firewall-config-box.js index 07a24931..ba61be1b 100644 --- a/web/public/js/components/server/http-firewall-config-box.js +++ b/web/public/js/components/server/http-firewall-config-box.js @@ -1,5 +1,5 @@ Vue.component("http-firewall-config-box", { - props: ["v-firewall-config", "v-is-location", "v-firewall-policy"], + props: ["v-firewall-config", "v-is-location", "v-is-group", "v-firewall-policy"], data: function () { let firewall = this.vFirewallConfig if (firewall == null) { @@ -17,12 +17,12 @@ Vue.component("http-firewall-config-box", { template: `
- - - + + +
WAF策略 -
{{vFirewallPolicy.name}}   [{{vFirewallPolicy.modeInfo.name}}]  +
{{vFirewallPolicy.name}}   [{{vFirewallPolicy.modeInfo.name}}] 

使用当前服务所在集群的设置。

当前集群没有设置WAF策略,当前配置无法生效。 diff --git a/web/public/js/components/server/http-header-policy-box.js b/web/public/js/components/server/http-header-policy-box.js index 067cc1f1..588fa5b0 100644 --- a/web/public/js/components/server/http-header-policy-box.js +++ b/web/public/js/components/server/http-header-policy-box.js @@ -1,5 +1,5 @@ Vue.component("http-header-policy-box", { - props: ["v-request-header-policy", "v-request-header-ref", "v-response-header-policy", "v-response-header-ref", "v-params", "v-is-location"], + props: ["v-request-header-policy", "v-request-header-ref", "v-response-header-policy", "v-response-header-ref", "v-params", "v-is-location", "v-is-group", "v-has-group-request-config", "v-has-group-response-config", "v-group-setting-url"], data: function () { let type = "request" let hash = window.location.hash @@ -127,7 +127,7 @@ Vue.component("http-header-policy-box", { -
+
@@ -135,41 +135,47 @@ Vue.component("http-header-policy-box", { -
+
+
+
+ 由于已经在当前服务分组中进行了对应的配置,在这里的配置将不会生效。 +
+

设置请求Header [添加新Header]

-

暂时还没有Header。

-
- - - - - +

暂时还没有Header。

+
名称操作
+ + + + + + + + + + + - - - - - - -
名称操作
{{header.name}}{{header.value}}修改   删除
{{header.name}}{{header.value}}修改   删除
- -

删除请求Header

-

这里可以设置需要从请求中删除的Header。

- - - - -
需要删除的Header -
-
{{headerName}}
-
-
- -
+
+ +

删除请求Header

+

这里可以设置需要从请求中删除的Header。

+ + + + +
需要删除的Header +
+
{{headerName}}
+
+
+ +
+
-
+
@@ -177,38 +183,44 @@ Vue.component("http-header-policy-box", { -
-

设置响应Header [添加新Header]

-

将会覆盖已有的同名Header。

-

暂时还没有Header。

-
- - - - - +
+
+
+ 由于已经在当前服务分组中进行了对应的配置,在这里的配置将不会生效。 +
+
+

设置响应Header [添加新Header]

+

将会覆盖已有的同名Header。

+

暂时还没有Header。

+
名称操作
+ + + + + + + + + + + - - - - - - -
名称操作
{{header.name}}{{header.value}}修改   删除
{{header.name}}{{header.value}}修改   删除
- -

删除响应Header

-

这里可以设置需要从响应中删除的Header。

- - - - -
需要删除的Header -
-
{{headerName}}
-
-
- -
+
+ +

删除响应Header

+

这里可以设置需要从响应中删除的Header。

+ + + + +
需要删除的Header +
+
{{headerName}}
+
+
+ +
+
` diff --git a/web/public/js/components/server/http-remote-addr-config-box.js b/web/public/js/components/server/http-remote-addr-config-box.js index ed4e625b..18b372fc 100644 --- a/web/public/js/components/server/http-remote-addr-config-box.js +++ b/web/public/js/components/server/http-remote-addr-config-box.js @@ -1,5 +1,5 @@ Vue.component("http-remote-addr-config-box", { - props: ["v-remote-addr-config", "v-is-location"], + props: ["v-remote-addr-config", "v-is-location", "v-is-group"], data: function () { let config = this.vRemoteAddrConfig if (config == null) { @@ -15,14 +15,14 @@ Vue.component("http-remote-addr-config-box", { }, methods: { isOn: function () { - return (!this.vIsLocation || this.config.isPrior) && this.config.isOn + return ((!this.vIsLocation && !this.vIsGroup) || this.config.isPrior) && this.config.isOn } }, template: `
- - + +
是否启用 diff --git a/web/public/js/components/server/http-stat-config-box.js b/web/public/js/components/server/http-stat-config-box.js index 919ece2b..67d2b4b4 100644 --- a/web/public/js/components/server/http-stat-config-box.js +++ b/web/public/js/components/server/http-stat-config-box.js @@ -1,5 +1,5 @@ Vue.component("http-stat-config-box", { - props: ["v-stat-config", "v-is-location"], + props: ["v-stat-config", "v-is-location", "v-is-group"], data: function () { let stat = this.vStatConfig if (stat == null) { @@ -15,8 +15,8 @@ Vue.component("http-stat-config-box", { template: `
- - + +
是否开启统计 diff --git a/web/public/js/components/server/http-web-root-box.js b/web/public/js/components/server/http-web-root-box.js index 2de7d1c6..681f3a2d 100644 --- a/web/public/js/components/server/http-web-root-box.js +++ b/web/public/js/components/server/http-web-root-box.js @@ -1,5 +1,5 @@ Vue.component("http-web-root-box", { - props: ["v-root-config", "v-is-location"], + props: ["v-root-config", "v-is-location", "v-is-group"], data: function () { let rootConfig = this.vRootConfig if (rootConfig == null) { @@ -38,14 +38,14 @@ Vue.component("http-web-root-box", { this.rootConfig.indexes.$remove(i) }, isOn: function () { - return (!this.vIsLocation || this.rootConfig.isPrior) && this.rootConfig.isOn + return ((!this.vIsLocation && !this.vIsGroup) || this.rootConfig.isPrior) && this.rootConfig.isOn } }, template: `
- - + +
是否开启静态资源分发 diff --git a/web/public/js/components/server/http-webp-config-box.js b/web/public/js/components/server/http-webp-config-box.js index ab03de33..b91e40d2 100644 --- a/web/public/js/components/server/http-webp-config-box.js +++ b/web/public/js/components/server/http-webp-config-box.js @@ -1,5 +1,5 @@ Vue.component("http-webp-config-box", { - props: ["v-webp-config", "v-is-location"], + props: ["v-webp-config", "v-is-location", "v-is-group"], data: function () { let config = this.vWebpConfig if (config == null) { @@ -43,7 +43,7 @@ Vue.component("http-webp-config-box", { }, methods: { isOn: function () { - return (!this.vIsLocation || this.config.isPrior) && this.config.isOn + return ((!this.vIsLocation && !this.vIsGroup) || this.config.isPrior) && this.config.isOn }, changeExtensions: function (values) { values.forEach(function (v, k) { @@ -66,8 +66,8 @@ Vue.component("http-webp-config-box", { template: `
- - + +
是否启用 diff --git a/web/public/js/components/server/http-websocket-box.js b/web/public/js/components/server/http-websocket-box.js index 92cd24b7..0623b66e 100644 --- a/web/public/js/components/server/http-websocket-box.js +++ b/web/public/js/components/server/http-websocket-box.js @@ -1,5 +1,5 @@ Vue.component("http-websocket-box", { - props: ["v-websocket-ref", "v-websocket-config", "v-is-location"], + props: ["v-websocket-ref", "v-websocket-config", "v-is-location", "v-is-group"], data: function () { let websocketRef = this.vWebsocketRef if (websocketRef == null) { @@ -55,7 +55,7 @@ Vue.component("http-websocket-box", { }, methods: { isOn: function () { - return (!this.vIsLocation || this.websocketRef.isPrior) && this.websocketRef.isOn + return ((!this.vIsLocation && !this.vIsGroup) || this.websocketRef.isPrior) && this.websocketRef.isOn }, changeAdvancedVisible: function (v) { this.advancedVisible = v @@ -77,8 +77,8 @@ Vue.component("http-websocket-box", { - - + + ` diff --git a/web/views/@default/@layout.css b/web/views/@default/@layout.css index 1d481e01..f125e4ef 100644 --- a/web/views/@default/@layout.css +++ b/web/views/@default/@layout.css @@ -187,7 +187,7 @@ p.margin { margin-top: 1em; } .opacity-mask { - opacity: 0.6; + opacity: 0.3; } /** 操作按钮容器 **/ .op.one { diff --git a/web/views/@default/@layout.less b/web/views/@default/@layout.less index ce408de6..609c318e 100644 --- a/web/views/@default/@layout.less +++ b/web/views/@default/@layout.less @@ -104,7 +104,7 @@ div.margin, p.margin { } .opacity-mask { - opacity: 0.6; + opacity: 0.3; } /** 操作按钮容器 **/ diff --git a/web/views/@default/servers/groups/group/settings/accessLog/index.html b/web/views/@default/servers/groups/group/settings/accessLog/index.html new file mode 100644 index 00000000..45dc72c8 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/accessLog/index.html @@ -0,0 +1,15 @@ +{$layout} +{$template "/servers/groups/group/menu"} +{$template "/left_menu_without_menu"} + +
+
+ + + + +
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/accessLog/index.js b/web/views/@default/servers/groups/group/settings/accessLog/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/accessLog/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/cache/@menu.html b/web/views/@default/servers/groups/group/settings/cache/@menu.html new file mode 100644 index 00000000..ebb46566 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/cache/@menu.html @@ -0,0 +1,5 @@ + + 设置 + 清理 + 预热 + \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/cache/createPopup.html b/web/views/@default/servers/groups/group/settings/cache/createPopup.html new file mode 100644 index 00000000..29055d9b --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/cache/createPopup.html @@ -0,0 +1,11 @@ +{$layout "layout_popup"} + +

添加缓存设置

+

添加不缓存设置

+ +
是否启用配置 diff --git a/web/public/js/components/server/prior-checkbox.js b/web/public/js/components/server/prior-checkbox.js index d84782be..427cddb9 100644 --- a/web/public/js/components/server/prior-checkbox.js +++ b/web/public/js/components/server/prior-checkbox.js @@ -18,7 +18,7 @@ Vue.component("prior-checkbox", { -

[已打开] 打开后可以覆盖父级配置。

+

[已打开] 打开后可以覆盖父级或子级配置。

+ +
+

如果请求满足当前添加的条件,则不缓存。

+ 确定 + \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/cache/createPopup.js b/web/views/@default/servers/groups/group/settings/cache/createPopup.js new file mode 100644 index 00000000..ffca28c1 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/cache/createPopup.js @@ -0,0 +1,9 @@ +Tea.context(function () { + this.success = NotifyPopup + this.cacheRef = null + + if (window.parent.UPDATING_CACHE_REF != null) { + this.cacheRef = window.parent.UPDATING_CACHE_REF + this.isReverse = this.cacheRef.isReverse + } +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/cache/index.html b/web/views/@default/servers/groups/group/settings/cache/index.html new file mode 100644 index 00000000..6da0b75f --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/cache/index.html @@ -0,0 +1,16 @@ +{$layout} +{$template "/servers/groups/group/menu"} +{$template "/left_menu_without_menu"} + +
+
+ + + +

修改条件设置后请记得保存。

+
+
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/cache/index.js b/web/views/@default/servers/groups/group/settings/cache/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/cache/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/cache/preheat.html b/web/views/@default/servers/groups/group/settings/cache/preheat.html new file mode 100644 index 00000000..c01baa93 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/cache/preheat.html @@ -0,0 +1,39 @@ +{$layout} +{$template "/left_menu"} + +
+ {$template "menu"} + +
+
+

没有开启缓存,不需要清理。

+
+
+

可以在这里批量预热一组Key。

+
+ + + + + + + + + + + +
Key列表 + +

每行一个Key。

+
操作结果 +
数据发送中...
+ 失败:{{message}} +
+ 此集群下没有任何可用的节点。 +
{{one.nodeName}}:{{one.message}}
+
+
+ 提交 +
+
+
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/cache/preheat.js b/web/views/@default/servers/groups/group/settings/cache/preheat.js new file mode 100644 index 00000000..121c5489 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/cache/preheat.js @@ -0,0 +1,26 @@ +Tea.context(function () { + this.isRequesting = false + this.isOk = false + this.message = "" + this.results = [] + + this.before = function () { + this.isRequesting = true + this.isOk = false + this.message = "" + this.results = [] + } + + this.success = function (resp) { + this.isOk = true + this.results = resp.data.results + } + + this.fail = function (resp) { + this.message = resp.message + } + + this.done = function () { + this.isRequesting = false + } +}); \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/cache/purge.html b/web/views/@default/servers/groups/group/settings/cache/purge.html new file mode 100644 index 00000000..54912971 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/cache/purge.html @@ -0,0 +1,51 @@ +{$layout} +{$template "/left_menu"} + +
+ {$template "menu"} + +
+
+

没有开启缓存,不需要清理。

+
+
+

可以在这里批量删除一组Key。

+ +
+ + + + + + + + + + + + + + + +
操作类型 + 根据Key   + 根据前缀 +
+ Key列表 + Key前缀列表 + + +

每行一个Key,比如是一个完整的URLhttps://example.com/hello/world.html

+

每行一个Key前缀,比如是一个URL前缀https://example.com/hello/

+
操作结果 +
数据发送中...
+ 失败:{{message}} +
+ 此集群下没有任何可用的节点。 +
{{one.nodeName}}:{{one.message}}
+
+
+ 提交 +
+
+
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/cache/purge.js b/web/views/@default/servers/groups/group/settings/cache/purge.js new file mode 100644 index 00000000..69899cf0 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/cache/purge.js @@ -0,0 +1,31 @@ +Tea.context(function () { + this.isRequesting = false + this.isOk = false + this.message = "" + this.results = [] + + this.before = function () { + this.isRequesting = true + this.isOk = false + this.message = "" + this.results = [] + } + + this.success = function (resp) { + this.isOk = true + this.results = resp.data.results + } + + this.fail = function (resp) { + this.message = resp.message + } + + this.done = function () { + this.isRequesting = false + } + + /** + * 操作类型 + */ + this.type = "key" // key | prefix +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/charset/index.html b/web/views/@default/servers/groups/group/settings/charset/index.html new file mode 100644 index 00000000..c643d844 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/charset/index.html @@ -0,0 +1,11 @@ +{$layout} +{$template "/servers/groups/group/menu"} +{$template "/left_menu_without_menu"} + +
+
+ + + +
+
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/charset/index.js b/web/views/@default/servers/groups/group/settings/charset/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/charset/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/compression/gzip/index.html b/web/views/@default/servers/groups/group/settings/compression/gzip/index.html new file mode 100644 index 00000000..949fed00 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/compression/gzip/index.html @@ -0,0 +1,15 @@ +{$layout} + +{$template "/left_menu"} + +
+
+ + + + + +
+ +
+
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/compression/gzip/index.js b/web/views/@default/servers/groups/group/settings/compression/gzip/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/compression/gzip/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/compression/index.html b/web/views/@default/servers/groups/group/settings/compression/index.html new file mode 100644 index 00000000..1a565abb --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/compression/index.html @@ -0,0 +1,13 @@ +{$layout} +{$template "/servers/groups/group/menu"} +{$template "/left_menu_without_menu"} + +
+
+ + + + + +
+
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/compression/index.js b/web/views/@default/servers/groups/group/settings/compression/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/compression/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/headers/index.html b/web/views/@default/servers/groups/group/settings/headers/index.html new file mode 100644 index 00000000..7a9832da --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/headers/index.html @@ -0,0 +1,16 @@ +{$layout} +{$template "/servers/groups/group/menu"} +{$template "/left_menu_without_menu"} + +
+
+ + +
+
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/headers/index.js b/web/views/@default/servers/groups/group/settings/headers/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/headers/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/remoteAddr/index.html b/web/views/@default/servers/groups/group/settings/remoteAddr/index.html new file mode 100644 index 00000000..79ca4966 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/remoteAddr/index.html @@ -0,0 +1,16 @@ +{$layout} +{$template "/servers/groups/group/menu"} +{$template "/left_menu_without_menu"} + +
+
+ + + + + + +
+
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/remoteAddr/index.js b/web/views/@default/servers/groups/group/settings/remoteAddr/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/remoteAddr/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/stat/index.html b/web/views/@default/servers/groups/group/settings/stat/index.html new file mode 100644 index 00000000..193a176f --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/stat/index.html @@ -0,0 +1,11 @@ +{$layout} +{$template "/servers/groups/group/menu"} +{$template "/left_menu_without_menu"} + +
+
+ + + +
+
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/stat/index.js b/web/views/@default/servers/groups/group/settings/stat/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/stat/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/@menu.html b/web/views/@default/servers/groups/group/settings/waf/@menu.html new file mode 100644 index 00000000..503f1178 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/@menu.html @@ -0,0 +1,11 @@ + + 设置 + 入站规则 + 出站规则 + | + 国家/地区封禁 + 省份封禁 + 白名单 + 黑名单 + IP检查 + \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/group.html b/web/views/@default/servers/groups/group/settings/waf/group.html new file mode 100644 index 00000000..8abcf2f1 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/group.html @@ -0,0 +1,70 @@ +{$layout} +{$template "/left_menu"} + +
+ {$template "menu"} + +

分组[修改]

+ + + + + + + + + + + + + +
名称{{group.name}}
描述 + 暂时还没有描述。 + {{group.description}} +
启用状态 + +
+ +

规则集[添加规则集]

+

暂时还没有规则。

+ + + + + + + + + + + + + + + + + + + + + +
规则集名称规则关系动作操作
{{set.name}} +

+ +

+
+
+ +
+ 暂时还没有规则 +
+ + ({{set.connector.toUpperCase()}}) + + + + 修改   停用启用   删除 +
+ +

所有规则匹配顺序为从上到下,可以拖动左侧的排序。

+
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/group.js b/web/views/@default/servers/groups/group/settings/waf/group.js new file mode 100644 index 00000000..5638a956 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/group.js @@ -0,0 +1,82 @@ +Tea.context(function () { + this.$delay(function () { + let that = this + sortTable(function () { + let setIds = [] + document + .querySelectorAll("tbody[data-set-id]") + .forEach(function (v) { + setIds.push(v.getAttribute("data-set-id")) + }) + that.$post("/servers/components/waf/sortSets") + .params({ + groupId: that.group.id, + setIds: setIds + }) + .success(function () { + teaweb.successToast("排序保存成功") + }) + }) + }) + + // 更改分组 + this.updateGroup = function (groupId) { + teaweb.popup("/servers/components/waf/updateGroupPopup?groupId=" + groupId, { + height: "16em", + callback: function () { + teaweb.success("保存成功", function () { + window.location.reload() + }) + } + }) + } + + // 创建规则集 + this.createSet = function (groupId) { + teaweb.popup("/servers/components/waf/createSetPopup?firewallPolicyId=" + this.firewallPolicyId + "&groupId=" + groupId + "&type=" + this.type, { + width: "50em", + height: "30em", + callback: function () { + teaweb.success("保存成功", function () { + window.location.reload() + }) + } + }) + } + + // 修改规则集 + this.updateSet = function (setId) { + teaweb.popup("/servers/components/waf/updateSetPopup?firewallPolicyId=" + this.firewallPolicyId + "&groupId=" + this.group.id + "&type=" + this.type + "&setId=" + setId, { + width: "50em", + height: "30em", + callback: function () { + teaweb.success("保存成功", function () { + window.location.reload() + }) + } + }) + } + + // 停用|启用规则集 + this.updateSetOn = function (setId, isOn) { + this.$post("/servers/components/waf/updateSetOn") + .params({ + setId: setId, + isOn: isOn ? 1 : 0 + }) + .refresh() + } + + // 删除规则集 + this.deleteSet = function (setId) { + let that = this + teaweb.confirm("确定要删除此规则集吗?", function () { + that.$post("/servers/components/waf/deleteSet") + .params({ + groupId: this.group.id, + setId: setId + }) + .refresh() + }) + } +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/groups.html b/web/views/@default/servers/groups/group/settings/waf/groups.html new file mode 100644 index 00000000..b1edc653 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/groups.html @@ -0,0 +1,50 @@ +{$layout} +{$template "/left_menu"} + +
+ {$template "menu"} + + + [添加分组] + + + 当前WAF未启用,设置将在[启用]后生效。 + +

暂时还没有规则分组。

+ + + + + + + + + + + + + + + + + + +
规则分组规则集操作
{{group.name}} +

{{group.description}}

+

+ 启用 + 停用 + 预置 + 自定义 +

+
+ {{group.countSets}} + + 详情   + 启用停用   + 删除 +
+ +

所有规则匹配顺序为从上到下,可以拖动左侧的排序。

+ +
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/groups.js b/web/views/@default/servers/groups/group/settings/waf/groups.js new file mode 100644 index 00000000..f98b7fb2 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/groups.js @@ -0,0 +1,68 @@ +Tea.context(function () { + // 排序 + this.$delay(function () { + let that = this + sortTable(function () { + let groupIds = [] + document.querySelectorAll("tbody[data-group-id]") + .forEach(function (v) { + groupIds.push(v.getAttribute("data-group-id")) + }) + + that.$post("/servers/components/waf/sortGroups") + .params({ + firewallPolicyId: that.firewallPolicyId, + type: that.type, + groupIds: groupIds + }) + .success(function () { + teaweb.successToast("排序保存成功") + }) + }) + }) + + // 启用 + this.enableGroup = function (groupId) { + this.$post("/servers/components/waf/updateGroupOn") + .params({ + groupId: groupId, + isOn: 1 + }) + .refresh() + + } + + // 停用 + this.disableGroup = function (groupId) { + this.$post("/servers/components/waf/updateGroupOn") + .params({ + groupId: groupId, + isOn: 0 + }) + .refresh() + } + + // 删除 + this.deleteGroup = function (groupId) { + teaweb.confirm("确定要删除此规则分组吗?", function () { + this.$post("/servers/components/waf/deleteGroup") + .params({ + firewallPolicyId: this.firewallPolicyId, + groupId: groupId + }) + .refresh() + }) + } + + // 添加分组 + this.createGroup = function (type) { + teaweb.popup("/servers/components/waf/createGroupPopup?firewallPolicyId=" + this.firewallPolicyId + "&type=" + type, { + height: "16em", + callback: function () { + teaweb.success("保存成功", function () { + window.location.reload() + }) + } + }) + } +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/index.html b/web/views/@default/servers/groups/group/settings/waf/index.html new file mode 100644 index 00000000..7f1450d1 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/index.html @@ -0,0 +1,11 @@ +{$layout} +{$template "/servers/groups/group/menu"} +{$template "/left_menu_without_menu"} + +
+
+ + + +
+
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/index.js b/web/views/@default/servers/groups/group/settings/waf/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/allowList.html b/web/views/@default/servers/groups/group/settings/waf/ipadmin/allowList.html new file mode 100644 index 00000000..74c696f2 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/allowList.html @@ -0,0 +1,25 @@ +{$layout} +{$template "/left_menu"} + +
+ {$template "../menu"} + + 尚未为当前用户开通此功能。 + + {$ if .featureIsOn} + + 添加IP + | +
+ | + ID: {{listId}}   +
+ + 当前WAF未启用,设置将在[启用]后生效。 + +

暂时还没有IP。

+ + +
+ {$end} +
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/allowList.js b/web/views/@default/servers/groups/group/settings/waf/ipadmin/allowList.js new file mode 100644 index 00000000..afe9668a --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/allowList.js @@ -0,0 +1,38 @@ +Tea.context(function () { + this.updateItem = function (itemId) { + teaweb.popup(Tea.url(".updateIPPopup?listId=" + this.listId, {itemId: itemId}), { + height: "26em", + callback: function () { + teaweb.success("保存成功", function () { + teaweb.reload() + }) + } + }) + } + + this.deleteItem = function (itemId) { + let that = this + teaweb.confirm("确定要删除这个IP吗?", function () { + that.$post(".deleteIP") + .params({ + "listId": this.listId, + "itemId": itemId + }) + .refresh() + }) + } + + /** + * 添加IP名单菜单 + */ + this.createIP = function (type) { + teaweb.popup("/servers/iplists/createIPPopup?listId=" + this.listId + '&type=' + type, { + height: "26em", + callback: function () { + teaweb.success("保存成功", function () { + teaweb.reload() + }) + } + }) + } +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/countries.css b/web/views/@default/servers/groups/group/settings/waf/ipadmin/countries.css new file mode 100644 index 00000000..1cd34e35 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/countries.css @@ -0,0 +1,16 @@ +.region-letter-group .item { + padding-left: 1em !important; + padding-right: 1em !important; +} +.country-group { + padding-bottom: 1em; +} +.country-group .country-list .item { + float: left; + width: 12em; + margin-bottom: 0.5em; +} +.country-group .country-list .item .checkbox label { + font-size: 12px !important; +} +/*# sourceMappingURL=countries.css.map */ \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/countries.css.map b/web/views/@default/servers/groups/group/settings/waf/ipadmin/countries.css.map new file mode 100644 index 00000000..6f08bd35 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/countries.css.map @@ -0,0 +1 @@ +{"version":3,"sources":["countries.less"],"names":[],"mappings":"AAAA,oBACC;EACC,4BAAA;EACA,6BAAA;;AAIF;EAaC,mBAAA;;AAbD,cACC,cACC;EACC,WAAA;EACA,WAAA;EACA,oBAAA;;AALH,cACC,cACC,MAKC,UAAU;EACT,0BAAA","file":"countries.css"} \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/countries.html b/web/views/@default/servers/groups/group/settings/waf/ipadmin/countries.html new file mode 100644 index 00000000..42c08fcc --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/countries.html @@ -0,0 +1,59 @@ +{$layout} +{$template "/left_menu"} + +
+ {$template "../menu"} + + 尚未为当前用户开通此功能。 + + {$ if .featureIsOn} + 当前WAF未启用,设置将在[启用]后生效。 + +
+ + + + + + + + + + +
已封禁 + 暂时没有选择封禁区域。 +
+ + ({{country.letter}}){{country.name}} +
+
选择封禁区域 + 选择区域 + + +
+
+

{{letter}}

+
+
+
+ + +
+
+
+
+
+
+
+ +
+ {$end} +
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/countries.js b/web/views/@default/servers/groups/group/settings/waf/ipadmin/countries.js new file mode 100644 index 00000000..b0ed60d1 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/countries.js @@ -0,0 +1,54 @@ +Tea.context(function () { + this.letterGroups = [ + "ABC", "DEF", "GHI", "JKL", "MNO", "PQR", "STU", "VWX", "YZ" + ]; + this.selectedGroup = "ABC" + this.letterCountries = {} + let that = this + this.countSelectedCountries = this.countries.$count(function (k, country) { + return country.isChecked + }) + this.countries.forEach(function (country) { + if (typeof (that.letterCountries[country.letter]) == "undefined") { + that.letterCountries[country.letter] = [] + } + that.letterCountries[country.letter].push(country) + }) + this.isCheckingAll = false + + this.selectGroup = function (group) { + this.selectedGroup = group + } + + this.selectCountry = function (country) { + country.isChecked = !country.isChecked + this.change() + } + + this.deselectCountry = function (country) { + country.isChecked = false + this.change() + } + + this.checkAll = function () { + this.isCheckingAll = !this.isCheckingAll + + this.countries.forEach(function (country) { + country.isChecked = that.isCheckingAll + }) + + this.change() + } + + this.success = function () { + teaweb.success("保存成功", function () { + teaweb.reload() + }) + } + + this.change = function () { + this.countSelectedCountries = this.countries.$count(function (k, country) { + return country.isChecked + }) + } +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/countries.less b/web/views/@default/servers/groups/group/settings/waf/ipadmin/countries.less new file mode 100644 index 00000000..f6774ab9 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/countries.less @@ -0,0 +1,22 @@ +.region-letter-group { + .item { + padding-left: 1em !important; + padding-right: 1em !important; + } +} + +.country-group { + .country-list { + .item { + float: left; + width: 12em; + margin-bottom: 0.5em; + + .checkbox label { + font-size: 12px !important; + } + } + } + + padding-bottom: 1em; +} \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/denyList.html b/web/views/@default/servers/groups/group/settings/waf/ipadmin/denyList.html new file mode 100644 index 00000000..0255ce29 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/denyList.html @@ -0,0 +1,25 @@ +{$layout} +{$template "/left_menu"} + +
+ {$template "../menu"} + + 尚未为当前用户开通此功能。 + + {$ if .featureIsOn} + + 添加IP + | +
+ | + ID: {{listId}}   +
+ + 当前WAF未启用,设置将在[启用]后生效。 + +

暂时还没有IP。

+ + +
+ {$end} +
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/denyList.js b/web/views/@default/servers/groups/group/settings/waf/ipadmin/denyList.js new file mode 100644 index 00000000..afe9668a --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/denyList.js @@ -0,0 +1,38 @@ +Tea.context(function () { + this.updateItem = function (itemId) { + teaweb.popup(Tea.url(".updateIPPopup?listId=" + this.listId, {itemId: itemId}), { + height: "26em", + callback: function () { + teaweb.success("保存成功", function () { + teaweb.reload() + }) + } + }) + } + + this.deleteItem = function (itemId) { + let that = this + teaweb.confirm("确定要删除这个IP吗?", function () { + that.$post(".deleteIP") + .params({ + "listId": this.listId, + "itemId": itemId + }) + .refresh() + }) + } + + /** + * 添加IP名单菜单 + */ + this.createIP = function (type) { + teaweb.popup("/servers/iplists/createIPPopup?listId=" + this.listId + '&type=' + type, { + height: "26em", + callback: function () { + teaweb.success("保存成功", function () { + teaweb.reload() + }) + } + }) + } +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/provinces.css b/web/views/@default/servers/groups/group/settings/waf/ipadmin/provinces.css new file mode 100644 index 00000000..99e6ff0c --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/provinces.css @@ -0,0 +1,9 @@ +.province-list .item { + float: left; + width: 12em; + margin-bottom: 0.5em; +} +.province-list .item .checkbox label { + font-size: 12px !important; +} +/*# sourceMappingURL=provinces.css.map */ \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/provinces.css.map b/web/views/@default/servers/groups/group/settings/waf/ipadmin/provinces.css.map new file mode 100644 index 00000000..777cb7a0 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/provinces.css.map @@ -0,0 +1 @@ +{"version":3,"sources":["provinces.less"],"names":[],"mappings":"AAAA,cACC;EACC,WAAA;EACA,WAAA;EACA,oBAAA;;AAJF,cACC,MAKC,UAAU;EACT,0BAAA","file":"provinces.css"} \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/provinces.html b/web/views/@default/servers/groups/group/settings/waf/ipadmin/provinces.html new file mode 100644 index 00000000..d1ea2261 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/provinces.html @@ -0,0 +1,54 @@ +{$layout} +{$template "/left_menu"} + +
+ {$template "../menu"} + + 尚未为当前用户开通此功能。 + + {$ if .featureIsOn} + 当前WAF未启用,设置将在[启用]后生效。 + +
+ + + + + + + + + + +
已封禁 + 暂时没有选择封禁省份。 +
+ + {{province.name}} +
+
选择封禁区域 + + + 选择省份/自治区 +
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+
+ +
+ {$end} +
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/provinces.js b/web/views/@default/servers/groups/group/settings/waf/ipadmin/provinces.js new file mode 100644 index 00000000..f2e83994 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/provinces.js @@ -0,0 +1,40 @@ +Tea.context(function () { + this.isCheckingAll = false + + this.countSelectedProvinces = this.provinces.$count(function (k, province) { + return province.isChecked + }) + + this.selectProvince = function (province) { + province.isChecked = !province.isChecked + this.change() + } + + this.deselectProvince = function (province) { + province.isChecked = false + this.change() + } + + this.checkAll = function () { + this.isCheckingAll = !this.isCheckingAll + let that = this + this.provinces.forEach(function (province) { + province.isChecked = that.isCheckingAll + }) + + this.change() + } + + this.success = function () { + teaweb.success("保存成功", function () { + teaweb.reload() + }) + } + + + this.change = function () { + this.countSelectedProvinces = this.provinces.$count(function (k, province) { + return province.isChecked + }) + } +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/provinces.less b/web/views/@default/servers/groups/group/settings/waf/ipadmin/provinces.less new file mode 100644 index 00000000..a9bc1668 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/provinces.less @@ -0,0 +1,11 @@ +.province-list { + .item { + float: left; + width: 12em; + margin-bottom: 0.5em; + + .checkbox label { + font-size: 12px !important; + } + } +} diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/test.html b/web/views/@default/servers/groups/group/settings/waf/ipadmin/test.html new file mode 100644 index 00000000..a37bfaee --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/test.html @@ -0,0 +1,55 @@ +{$layout} +{$template "/left_menu"} + +
+ {$template "../menu"} + + 尚未为当前用户开通此功能。 + + {$ if .featureIsOn} + 当前WAF未启用,设置将在[启用]后生效。 + +
+ + + + + + + + + + +
IP * + +

要检查的IP

+
检查结果 +
+
+ {{result.error}} +
+
+
+
+ 在白名单中   +
+
+ 在黑名单中   +
+
+
+ 在省份封禁中 "{{result.province.name}}" +
+
+ 在国家/地区封禁中 "{{result.country.name}}" +
+
+
+ 没有找到和{{ip}}匹配的配置。 +
+
+
+ 检查IP状态 +
+ {$end} +
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/test.js b/web/views/@default/servers/groups/group/settings/waf/ipadmin/test.js new file mode 100644 index 00000000..822ad934 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/test.js @@ -0,0 +1,35 @@ +Tea.context(function () { + this.ip = "" + this.result = { + isDone: false, + isOk: false, + isFound: false, + isAllowed: false, + error: "", + province: null, + country: null, + ipItem: null, + ipList: null + } + + this.$delay(function () { + this.$watch("ip", function () { + this.result.isDone = false + }) + }) + + this.success = function (resp) { + this.result = resp.data.result + } + + this.updateItem = function (listId, itemId) { + teaweb.popup(Tea.url(".updateIPPopup?listId=" + listId, {itemId: itemId}), { + height: "26em", + callback: function () { + teaweb.success("保存成功", function () { + + }) + } + }) + } +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/waf/ipadmin/updateIPPopup.html b/web/views/@default/servers/groups/group/settings/waf/ipadmin/updateIPPopup.html new file mode 100644 index 00000000..8ab5ebc8 --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/waf/ipadmin/updateIPPopup.html @@ -0,0 +1,77 @@ +{$layout "layout_popup"} + +

修改IP

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
类型 * + + IPv4 + IPv6 + 所有IP + +

单个IPv4或一个IPv4范围。

+

单个IPv6。

+

允许或禁用所有的IP。

+
开始IP * + +
结束IP + +

表示IP段的时候需要填写此项。

+
IP * + +

IPv6地址,比如 1406:3c00:0:2409:13:58:103:15

+
级别 + +
过期时间 + +

在加入名单某一段时间后会失效,留空表示永久有效。

+
备注
+ +
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/web/index.html b/web/views/@default/servers/groups/group/settings/web/index.html new file mode 100644 index 00000000..3ac5060b --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/web/index.html @@ -0,0 +1,11 @@ +{$layout} +{$template "/servers/groups/group/menu"} +{$template "/left_menu_without_menu"} + +
+
+ + + +
+
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/web/index.js b/web/views/@default/servers/groups/group/settings/web/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/web/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/webp/index.html b/web/views/@default/servers/groups/group/settings/webp/index.html new file mode 100644 index 00000000..5b85456f --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/webp/index.html @@ -0,0 +1,14 @@ +{$layout} +{$template "/servers/groups/group/menu"} +{$template "/left_menu_without_menu"} + +
+
+ + + + + + +
+
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/webp/index.js b/web/views/@default/servers/groups/group/settings/webp/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/webp/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/websocket/index.html b/web/views/@default/servers/groups/group/settings/websocket/index.html new file mode 100644 index 00000000..4402725b --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/websocket/index.html @@ -0,0 +1,11 @@ +{$layout} +{$template "/servers/groups/group/menu"} +{$template "/left_menu_without_menu"} + +
+
+ + + +
+
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/websocket/index.js b/web/views/@default/servers/groups/group/settings/websocket/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/websocket/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/cache/index.html b/web/views/@default/servers/server/settings/cache/index.html index 655a5505..2da21fcd 100644 --- a/web/views/@default/servers/server/settings/cache/index.html +++ b/web/views/@default/servers/server/settings/cache/index.html @@ -4,10 +4,17 @@
{$template "menu"} -
- - - -

修改条件设置后请记得保存。

-
+
+
+ 由于已经在当前服务分组中进行了对应的配置,在这里的配置将不会生效。 +
+ +
+
+ + + +

修改条件设置后请记得保存。

+
+
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/charset/index.html b/web/views/@default/servers/server/settings/charset/index.html index cf2091f8..b9b6ee6b 100644 --- a/web/views/@default/servers/server/settings/charset/index.html +++ b/web/views/@default/servers/server/settings/charset/index.html @@ -3,9 +3,16 @@ {$template "/left_menu"}
-
- - - -
+
+
+ 由于已经在当前服务分组中进行了对应的配置,在这里的配置将不会生效。 +
+ +
+
+ + + +
+
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/compression/index.html b/web/views/@default/servers/server/settings/compression/index.html index d87bedbc..125bd5bb 100644 --- a/web/views/@default/servers/server/settings/compression/index.html +++ b/web/views/@default/servers/server/settings/compression/index.html @@ -2,11 +2,18 @@ {$template "/left_menu"}
-
- - +
+
+ 由于已经在当前服务分组中进行了对应的配置,在这里的配置将不会生效。 +
- - -
+
+
+ + + + + +
+
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/headers/createSetPopup.html b/web/views/@default/servers/server/settings/headers/createSetPopup.html index f9909bf3..6a9a23a5 100644 --- a/web/views/@default/servers/server/settings/headers/createSetPopup.html +++ b/web/views/@default/servers/server/settings/headers/createSetPopup.html @@ -2,7 +2,6 @@

设置Header

- diff --git a/web/views/@default/servers/server/settings/headers/index.html b/web/views/@default/servers/server/settings/headers/index.html index ba7b1f5c..aeb6026f 100644 --- a/web/views/@default/servers/server/settings/headers/index.html +++ b/web/views/@default/servers/server/settings/headers/index.html @@ -3,5 +3,11 @@ {$template "/left_menu"}
- +
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/headers/updateSetPopup.html b/web/views/@default/servers/server/settings/headers/updateSetPopup.html index 186c6a9c..84e50c9a 100644 --- a/web/views/@default/servers/server/settings/headers/updateSetPopup.html +++ b/web/views/@default/servers/server/settings/headers/updateSetPopup.html @@ -2,7 +2,6 @@

修改Header

-
diff --git a/web/views/@default/servers/server/settings/remoteAddr/index.html b/web/views/@default/servers/server/settings/remoteAddr/index.html index ea2f88fd..78718c6e 100644 --- a/web/views/@default/servers/server/settings/remoteAddr/index.html +++ b/web/views/@default/servers/server/settings/remoteAddr/index.html @@ -2,12 +2,19 @@ {$template "/left_menu"}
- - - +
+
+ 由于已经在当前服务分组中进行了对应的配置,在这里的配置将不会生效。 +
- +
+ + + - - + + + + +
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/stat/index.html b/web/views/@default/servers/server/settings/stat/index.html index c6525d11..3f1e1240 100644 --- a/web/views/@default/servers/server/settings/stat/index.html +++ b/web/views/@default/servers/server/settings/stat/index.html @@ -3,9 +3,16 @@ {$template "/left_menu"}
-
- - - - +
+
+ 由于已经在当前服务分组中进行了对应的配置,在这里的配置将不会生效。 +
+ +
+
+ + + + +
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/waf/index.html b/web/views/@default/servers/server/settings/waf/index.html index 2b317e7c..125fabac 100644 --- a/web/views/@default/servers/server/settings/waf/index.html +++ b/web/views/@default/servers/server/settings/waf/index.html @@ -2,10 +2,18 @@ {$template "/left_menu"}
- {$template "menu"} -
- - - - +
+
+ 由于已经在当前服务分组中进行了对应的配置,在这里的配置将不会生效。 +
+ +
+ {$template "menu"} + +
+ + + + +
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/web/index.html b/web/views/@default/servers/server/settings/web/index.html index ee375204..81961cbe 100644 --- a/web/views/@default/servers/server/settings/web/index.html +++ b/web/views/@default/servers/server/settings/web/index.html @@ -3,9 +3,16 @@ {$template "/left_menu"}
-
- - - - +
+
+ 由于已经在当前服务分组中进行了对应的配置,在这里的配置将不会生效。 +
+ +
+
+ + + + +
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/webp/index.html b/web/views/@default/servers/server/settings/webp/index.html index 0133c589..f1e788d3 100644 --- a/web/views/@default/servers/server/settings/webp/index.html +++ b/web/views/@default/servers/server/settings/webp/index.html @@ -2,12 +2,19 @@ {$template "/left_menu"}
-
- - +
+
+ 由于已经在当前服务分组中进行了对应的配置,在这里的配置将不会生效。 +
- +
+ + + - - + + + + +
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/websocket/index.html b/web/views/@default/servers/server/settings/websocket/index.html index 495f4553..79ca94bb 100644 --- a/web/views/@default/servers/server/settings/websocket/index.html +++ b/web/views/@default/servers/server/settings/websocket/index.html @@ -3,9 +3,16 @@ {$template "/left_menu"}
-
- - - - +
+
+ 由于已经在当前服务分组中进行了对应的配置,在这里的配置将不会生效。 +
+ +
+
+ + + + +
\ No newline at end of file