diff --git a/internal/web/actions/default/servers/components/waf/ipadmin/provinces.go b/internal/web/actions/default/servers/components/waf/ipadmin/provinces.go index 4fa3a200..6f991028 100644 --- a/internal/web/actions/default/servers/components/waf/ipadmin/provinces.go +++ b/internal/web/actions/default/servers/components/waf/ipadmin/provinces.go @@ -7,13 +7,12 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/regionconfigs" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/maps" ) -const ChinaCountryId = 1 - type ProvincesAction struct { actionutils.ParentAction } @@ -43,7 +42,7 @@ func (this *ProvincesAction) RunGet(params struct { } provincesResp, err := this.RPC().RegionProvinceRPC().FindAllRegionProvincesWithRegionCountryId(this.AdminContext(), &pb.FindAllRegionProvincesWithRegionCountryIdRequest{ - RegionCountryId: int64(ChinaCountryId), + RegionCountryId: regionconfigs.RegionChinaId, }) if err != nil { this.ErrorPage(err) 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 index 4d894063..26ff3ba5 100644 --- 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 @@ -12,8 +12,6 @@ import ( "github.com/iwind/TeaGo/maps" ) -const ChinaCountryId = 1 - type ProvincesAction struct { actionutils.ParentAction } diff --git a/internal/web/actions/default/servers/server/settings/waf/init.go b/internal/web/actions/default/servers/server/settings/waf/init.go index e86a4c5e..8a26e942 100644 --- a/internal/web/actions/default/servers/server/settings/waf/init.go +++ b/internal/web/actions/default/servers/server/settings/waf/init.go @@ -18,6 +18,8 @@ func init() { Get("/ipadmin/allowList", new(ipadmin.AllowListAction)). Get("/ipadmin/denyList", new(ipadmin.DenyListAction)). GetPost("/ipadmin/countries", new(ipadmin.CountriesAction)). + Get("/ipadmin/selectCountriesPopup", new(ipadmin.SelectCountriesPopupAction)). + Get("/ipadmin/selectProvincesPopup", new(ipadmin.SelectProvincesPopupAction)). GetPost("/ipadmin/provinces", new(ipadmin.ProvincesAction)). GetPost("/ipadmin/updateIPPopup", new(ipadmin.UpdateIPPopupAction)). Post("/ipadmin/deleteIP", new(ipadmin.DeleteIPAction)). diff --git a/internal/web/actions/default/servers/server/settings/waf/ipadmin/countries.go b/internal/web/actions/default/servers/server/settings/waf/ipadmin/countries.go index e2f0a09e..8d587063 100644 --- a/internal/web/actions/default/servers/server/settings/waf/ipadmin/countries.go +++ b/internal/web/actions/default/servers/server/settings/waf/ipadmin/countries.go @@ -42,9 +42,11 @@ func (this *CountriesAction) RunGet(params struct { this.NotFound("firewallPolicy", params.FirewallPolicyId) return } - var selectedCountryIds = []int64{} + var deniedCountryIds = []int64{} + var allowedCountryIds = []int64{} if policyConfig.Inbound != nil && policyConfig.Inbound.Region != nil { - selectedCountryIds = policyConfig.Inbound.Region.DenyCountryIds + deniedCountryIds = policyConfig.Inbound.Region.DenyCountryIds + allowedCountryIds = policyConfig.Inbound.Region.AllowCountryIds } countriesResp, err := this.RPC().RegionCountryRPC().FindAllRegionCountries(this.AdminContext(), &pb.FindAllRegionCountriesRequest{}) @@ -52,16 +54,23 @@ func (this *CountriesAction) RunGet(params struct { this.ErrorPage(err) return } - var countryMaps = []maps.Map{} + var deniesCountryMaps = []maps.Map{} + var allowedCountryMaps = []maps.Map{} for _, country := range countriesResp.RegionCountries { - countryMaps = append(countryMaps, maps.Map{ - "id": country.Id, - "name": country.DisplayName, - "letter": strings.ToUpper(string(country.Pinyin[0][0])), - "isChecked": lists.ContainsInt64(selectedCountryIds, country.Id), - }) + var countryMap = maps.Map{ + "id": country.Id, + "name": country.DisplayName, + "letter": strings.ToUpper(string(country.Pinyin[0][0])), + } + if lists.ContainsInt64(deniedCountryIds, country.Id) { + deniesCountryMaps = append(deniesCountryMaps, countryMap) + } + if lists.ContainsInt64(allowedCountryIds, country.Id) { + allowedCountryMaps = append(allowedCountryMaps, countryMap) + } } - this.Data["countries"] = countryMaps + this.Data["deniedCountries"] = deniesCountryMaps + this.Data["allowedCountries"] = allowedCountryMaps // except & only URL Patterns this.Data["exceptURLPatterns"] = []*shared.URLPattern{} @@ -88,7 +97,8 @@ func (this *CountriesAction) RunGet(params struct { func (this *CountriesAction) RunPost(params struct { FirewallPolicyId int64 - CountryIds []int64 + DenyCountryIds []int64 + AllowCountryIds []int64 ExceptURLPatternsJSON []byte OnlyURLPatternsJSON []byte @@ -98,6 +108,8 @@ func (this *CountriesAction) RunPost(params struct { // 日志 defer this.CreateLogInfo(codes.WAF_LogUpdateForbiddenCountries, params.FirewallPolicyId) + // TODO validate denied and allowed countries + policyConfig, err := dao.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicyConfig(this.AdminContext(), params.FirewallPolicyId) if err != nil { this.ErrorPage(err) @@ -116,7 +128,8 @@ func (this *CountriesAction) RunPost(params struct { IsOn: true, } } - policyConfig.Inbound.Region.DenyCountryIds = params.CountryIds + policyConfig.Inbound.Region.DenyCountryIds = params.DenyCountryIds + policyConfig.Inbound.Region.AllowCountryIds = params.AllowCountryIds // 例外URL var exceptURLPatterns = []*shared.URLPattern{} diff --git a/internal/web/actions/default/servers/server/settings/waf/ipadmin/provinces.go b/internal/web/actions/default/servers/server/settings/waf/ipadmin/provinces.go index cb2070a5..d2f2f2a3 100644 --- a/internal/web/actions/default/servers/server/settings/waf/ipadmin/provinces.go +++ b/internal/web/actions/default/servers/server/settings/waf/ipadmin/provinces.go @@ -7,14 +7,13 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/regionconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/maps" ) -const ChinaCountryId = 1 - type ProvincesAction struct { actionutils.ParentAction } @@ -42,27 +41,36 @@ func (this *ProvincesAction) RunGet(params struct { this.NotFound("firewallPolicy", params.FirewallPolicyId) return } - var selectedProvinceIds = []int64{} + var deniedProvinceIds = []int64{} + var allowedProvinceIds = []int64{} if policyConfig.Inbound != nil && policyConfig.Inbound.Region != nil { - selectedProvinceIds = policyConfig.Inbound.Region.DenyProvinceIds + deniedProvinceIds = policyConfig.Inbound.Region.DenyProvinceIds + allowedProvinceIds = policyConfig.Inbound.Region.AllowProvinceIds } provincesResp, err := this.RPC().RegionProvinceRPC().FindAllRegionProvincesWithRegionCountryId(this.AdminContext(), &pb.FindAllRegionProvincesWithRegionCountryIdRequest{ - RegionCountryId: int64(ChinaCountryId), + RegionCountryId: regionconfigs.RegionChinaId, }) if err != nil { this.ErrorPage(err) return } - var provinceMaps = []maps.Map{} + var deniedProvinceMaps = []maps.Map{} + var allowedProvinceMaps = []maps.Map{} for _, province := range provincesResp.RegionProvinces { - provinceMaps = append(provinceMaps, maps.Map{ - "id": province.Id, - "name": province.DisplayName, - "isChecked": lists.ContainsInt64(selectedProvinceIds, province.Id), - }) + var provinceMap = maps.Map{ + "id": province.Id, + "name": province.DisplayName, + } + if lists.ContainsInt64(deniedProvinceIds, province.Id) { + deniedProvinceMaps = append(deniedProvinceMaps, provinceMap) + } + if lists.ContainsInt64(allowedProvinceIds, province.Id) { + allowedProvinceMaps = append(allowedProvinceMaps, provinceMap) + } } - this.Data["provinces"] = provinceMaps + this.Data["deniedProvinces"] = deniedProvinceMaps + this.Data["allowedProvinces"] = allowedProvinceMaps // except & only URL Patterns this.Data["exceptURLPatterns"] = []*shared.URLPattern{} @@ -89,7 +97,8 @@ func (this *ProvincesAction) RunGet(params struct { func (this *ProvincesAction) RunPost(params struct { FirewallPolicyId int64 - ProvinceIds []int64 + DenyProvinceIds []int64 + AllowProvinceIds []int64 ExceptURLPatternsJSON []byte OnlyURLPatternsJSON []byte @@ -117,7 +126,8 @@ func (this *ProvincesAction) RunPost(params struct { IsOn: true, } } - policyConfig.Inbound.Region.DenyProvinceIds = params.ProvinceIds + policyConfig.Inbound.Region.DenyProvinceIds = params.DenyProvinceIds + policyConfig.Inbound.Region.AllowProvinceIds = params.AllowProvinceIds // 例外URL var exceptURLPatterns = []*shared.URLPattern{} diff --git a/internal/web/actions/default/servers/server/settings/waf/ipadmin/selectCountriesPopup.go b/internal/web/actions/default/servers/server/settings/waf/ipadmin/selectCountriesPopup.go new file mode 100644 index 00000000..a1357ac6 --- /dev/null +++ b/internal/web/actions/default/servers/server/settings/waf/ipadmin/selectCountriesPopup.go @@ -0,0 +1,53 @@ +// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn . + +package ipadmin + +import ( + "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/lists" + "github.com/iwind/TeaGo/maps" + "strings" +) + +type SelectCountriesPopupAction struct { + actionutils.ParentAction +} + +func (this *SelectCountriesPopupAction) Init() { + this.Nav("", "", "") +} + +func (this *SelectCountriesPopupAction) RunGet(params struct { + Type string + SelectedCountryIds string +}) { + this.Data["type"] = params.Type + + var selectedCountryIds = utils.SplitNumbers(params.SelectedCountryIds) + + countriesResp, err := this.RPC().RegionCountryRPC().FindAllRegionCountries(this.AdminContext(), &pb.FindAllRegionCountriesRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + + // special regions + + var countryMaps = []maps.Map{} + for _, country := range countriesResp.RegionCountries { + countryMaps = append(countryMaps, maps.Map{ + "id": country.Id, + "name": country.DisplayName, + "letter": strings.ToUpper(string(country.Pinyin[0][0])), + "pinyin": country.Pinyin, + "codes": country.Codes, + "isCommon": country.IsCommon, + "isChecked": lists.ContainsInt64(selectedCountryIds, country.Id), + }) + } + this.Data["countries"] = countryMaps + + this.Show() +} diff --git a/internal/web/actions/default/servers/server/settings/waf/ipadmin/selectProvincesPopup.go b/internal/web/actions/default/servers/server/settings/waf/ipadmin/selectProvincesPopup.go new file mode 100644 index 00000000..28db774c --- /dev/null +++ b/internal/web/actions/default/servers/server/settings/waf/ipadmin/selectProvincesPopup.go @@ -0,0 +1,48 @@ +// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn . + +package ipadmin + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/utils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/regionconfigs" + "github.com/iwind/TeaGo/lists" + "github.com/iwind/TeaGo/maps" +) + +type SelectProvincesPopupAction struct { + actionutils.ParentAction +} + +func (this *SelectProvincesPopupAction) Init() { + this.Nav("", "", "") +} + +func (this *SelectProvincesPopupAction) RunGet(params struct { + Type string + SelectedProvinceIds string +}) { + this.Data["type"] = params.Type + + var selectedProvinceIds = utils.SplitNumbers(params.SelectedProvinceIds) + + provincesResp, err := this.RPC().RegionProvinceRPC().FindAllRegionProvincesWithRegionCountryId(this.AdminContext(), &pb.FindAllRegionProvincesWithRegionCountryIdRequest{ + RegionCountryId: regionconfigs.RegionChinaId, + }) + if err != nil { + this.ErrorPage(err) + return + } + var provinceMaps = []maps.Map{} + for _, province := range provincesResp.RegionProvinces { + provinceMaps = append(provinceMaps, maps.Map{ + "id": province.Id, + "name": province.DisplayName, + "isChecked": lists.ContainsInt64(selectedProvinceIds, province.Id), + }) + } + this.Data["provinces"] = provinceMaps + + this.Show() +} diff --git a/internal/web/actions/default/ui/provinceOptions.go b/internal/web/actions/default/ui/provinceOptions.go index 4c967d0b..50aae388 100644 --- a/internal/web/actions/default/ui/provinceOptions.go +++ b/internal/web/actions/default/ui/provinceOptions.go @@ -5,6 +5,7 @@ package ui import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/regionconfigs" "github.com/iwind/TeaGo/maps" ) @@ -13,7 +14,7 @@ type ProvinceOptionsAction struct { } func (this *ProvinceOptionsAction) RunPost(params struct{}) { - provincesResp, err := this.RPC().RegionProvinceRPC().FindAllRegionProvincesWithRegionCountryId(this.AdminContext(), &pb.FindAllRegionProvincesWithRegionCountryIdRequest{RegionCountryId: ChinaCountryId}) + provincesResp, err := this.RPC().RegionProvinceRPC().FindAllRegionProvincesWithRegionCountryId(this.AdminContext(), &pb.FindAllRegionProvincesWithRegionCountryIdRequest{RegionCountryId: regionconfigs.RegionChinaId}) if err != nil { this.ErrorPage(err) return diff --git a/internal/web/actions/default/ui/selectProvincesPopup.go b/internal/web/actions/default/ui/selectProvincesPopup.go index d90be1d8..f6ea5775 100644 --- a/internal/web/actions/default/ui/selectProvincesPopup.go +++ b/internal/web/actions/default/ui/selectProvincesPopup.go @@ -4,13 +4,12 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/utils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/regionconfigs" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/maps" ) -const ChinaCountryId = 1 - type SelectProvincesPopupAction struct { actionutils.ParentAction } @@ -24,7 +23,7 @@ func (this *SelectProvincesPopupAction) RunGet(params struct { }) { var selectedProvinceIds = utils.SplitNumbers(params.ProvinceIds) - provincesResp, err := this.RPC().RegionProvinceRPC().FindAllRegionProvincesWithRegionCountryId(this.AdminContext(), &pb.FindAllRegionProvincesWithRegionCountryIdRequest{RegionCountryId: ChinaCountryId}) + provincesResp, err := this.RPC().RegionProvinceRPC().FindAllRegionProvincesWithRegionCountryId(this.AdminContext(), &pb.FindAllRegionProvincesWithRegionCountryIdRequest{RegionCountryId: regionconfigs.RegionChinaId}) if err != nil { this.ErrorPage(err) return diff --git a/web/public/js/components/common/search-box.js b/web/public/js/components/common/search-box.js new file mode 100644 index 00000000..e597b072 --- /dev/null +++ b/web/public/js/components/common/search-box.js @@ -0,0 +1,33 @@ +Vue.component("search-box", { + props: ["placeholder", "width"], + data: function () { + let width = this.width + if (width == null) { + width = "10em" + } + return { + realWidth: width, + realValue: "" + } + }, + methods: { + onInput: function () { + this.$emit("input", { value: this.realValue}) + this.$emit("change", { value: this.realValue}) + }, + clearValue: function () { + this.realValue = "" + this.focus() + this.onInput() + }, + focus: function () { + this.$refs.valueRef.focus() + } + }, + template: `
` +}) \ No newline at end of file diff --git a/web/public/js/components/server/http-firewall-province-selector.js b/web/public/js/components/server/http-firewall-province-selector.js new file mode 100644 index 00000000..9eaf8a99 --- /dev/null +++ b/web/public/js/components/server/http-firewall-province-selector.js @@ -0,0 +1,55 @@ +Vue.component("http-firewall-province-selector", { + props: ["v-type", "v-provinces"], + data: function () { + let provinces = this.vProvinces + if (provinces == null) { + provinces = [] + } + + return { + listType: this.vType, + provinces: provinces + } + }, + methods: { + addProvince: function () { + let selectedProvinceIds = this.provinces.map(function (province) { + return province.id + }) + let that = this + teaweb.popup("/servers/server/settings/waf/ipadmin/selectProvincesPopup?type=" + this.listType + "&selectedProvinceIds=" + selectedProvinceIds.join(","), { + width: "50em", + height: "26em", + callback: function (resp) { + that.provinces = resp.data.selectedProvinces + that.$forceUpdate() + that.notifyChange() + } + }) + }, + removeProvince: function (index) { + this.provinces.$remove(index) + this.notifyChange() + }, + resetProvinces: function () { + this.provinces = [] + this.notifyChange() + }, + notifyChange: function () { + this.$emit("change", { + "provinces": this.provinces + }) + } + }, + template: `` +}) \ No newline at end of file diff --git a/web/public/js/components/server/http-firewall-region-selector.js b/web/public/js/components/server/http-firewall-region-selector.js new file mode 100644 index 00000000..53a77923 --- /dev/null +++ b/web/public/js/components/server/http-firewall-region-selector.js @@ -0,0 +1,55 @@ +Vue.component("http-firewall-region-selector", { + props: ["v-type", "v-countries"], + data: function () { + let countries = this.vCountries + if (countries == null) { + countries = [] + } + + return { + listType: this.vType, + countries: countries + } + }, + methods: { + addCountry: function () { + let selectedCountryIds = this.countries.map(function (country) { + return country.id + }) + let that = this + teaweb.popup("/servers/server/settings/waf/ipadmin/selectCountriesPopup?type=" + this.listType + "&selectedCountryIds=" + selectedCountryIds.join(","), { + width: "52em", + height: "30em", + callback: function (resp) { + that.countries = resp.data.selectedCountries + that.$forceUpdate() + that.notifyChange() + } + }) + }, + removeCountry: function (index) { + this.countries.$remove(index) + this.notifyChange() + }, + resetCountries: function () { + this.countries = [] + this.notifyChange() + }, + notifyChange: function () { + this.$emit("change", { + "countries": this.countries + }) + } + }, + template: `` +}) \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/waf/ipadmin/countries.css b/web/views/@default/servers/server/settings/waf/ipadmin/countries.css deleted file mode 100644 index aa3b2c53..00000000 --- a/web/views/@default/servers/server/settings/waf/ipadmin/countries.css +++ /dev/null @@ -1,17 +0,0 @@ -.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; - cursor: pointer !important; -} -/*# sourceMappingURL=countries.css.map */ \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/waf/ipadmin/countries.css.map b/web/views/@default/servers/server/settings/waf/ipadmin/countries.css.map deleted file mode 100644 index 15d53e6c..00000000 --- a/web/views/@default/servers/server/settings/waf/ipadmin/countries.css.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["countries.less"],"names":[],"mappings":"AAAA,oBACC;EACC,4BAAA;EACA,6BAAA;;AAIF;EAcC,mBAAA;;AAdD,cACC,cACC;EACC,WAAA;EACA,WAAA;EACA,oBAAA;;AALH,cACC,cACC,MAKC,UAAU;EACT,0BAAA;EACA,0BAAA","file":"countries.css"} \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/waf/ipadmin/countries.html b/web/views/@default/servers/server/settings/waf/ipadmin/countries.html index 0b530e97..71ca74ba 100644 --- a/web/views/@default/servers/server/settings/waf/ipadmin/countries.html +++ b/web/views/@default/servers/server/settings/waf/ipadmin/countries.html @@ -15,54 +15,32 @@| 已封禁 | -- 暂时没有选择封禁区域。 - - | -||
| 选择封禁区域 * | -
-
-
-
-
- {{letter}}-
-
-
-
-
-
-
-
-
- |
- ||
| 例外URL |
- 仅允许的区域 | +
+ |
|
| 限制URL |
- 仅封禁的区域 | +
+ 由于你已设置"仅允许的区域",所以不需要再设置封禁区域。 + |
|
| 例外URL |
+ |||
| 限制URL |
+ |||
| 已封禁 | -- 暂时没有选择封禁省份。 - - | -||
| 选择封禁区域 | -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- |
- ||
| 例外URL |
- 仅允许的省份 | +
+ |
|
| 限制URL |
- 仅封禁的省份 | +
+ 由于你已设置"仅允许的省份",所以不需要再设置封禁省份。 + |
|
| 例外URL |
+ |||
| 限制URL |
+ |||