改进WAF策略的区域封禁

This commit is contained in:
刘祥超
2023-07-07 15:28:29 +08:00
parent 981d1c626b
commit a5e97fc425
14 changed files with 383 additions and 356 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
@@ -36,9 +37,12 @@ func (this *IndexAction) RunGet(params struct {
this.NotFound("firewallPolicy", params.FirewallPolicyId) this.NotFound("firewallPolicy", params.FirewallPolicyId)
return return
} }
var selectedCountryIds = []int64{}
var deniedCountryIds = []int64{}
var allowedCountryIds = []int64{}
if policyConfig.Inbound != nil && policyConfig.Inbound.Region != nil { 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{}) countriesResp, err := this.RPC().RegionCountryRPC().FindAllRegionCountries(this.AdminContext(), &pb.FindAllRegionCountriesRequest{})
@@ -46,23 +50,46 @@ func (this *IndexAction) RunGet(params struct {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
var countryMaps = []maps.Map{} var deniesCountryMaps = []maps.Map{}
var allowedCountryMaps = []maps.Map{}
for _, country := range countriesResp.RegionCountries { for _, country := range countriesResp.RegionCountries {
countryMaps = append(countryMaps, maps.Map{ var countryMap = maps.Map{
"id": country.Id, "id": country.Id,
"name": country.DisplayName, "name": country.DisplayName,
"letter": strings.ToUpper(string(country.Pinyin[0][0])), "letter": strings.ToUpper(string(country.Pinyin[0][0])),
"isChecked": lists.ContainsInt64(selectedCountryIds, country.Id), }
}) if lists.ContainsInt64(deniedCountryIds, country.Id) {
deniesCountryMaps = append(deniesCountryMaps, countryMap)
}
if lists.ContainsInt64(allowedCountryIds, country.Id) {
allowedCountryMaps = append(allowedCountryMaps, countryMap)
}
}
this.Data["deniedCountries"] = deniesCountryMaps
this.Data["allowedCountries"] = allowedCountryMaps
// except & only URL Patterns
this.Data["exceptURLPatterns"] = []*shared.URLPattern{}
this.Data["onlyURLPatterns"] = []*shared.URLPattern{}
if policyConfig.Inbound != nil && policyConfig.Inbound.Region != nil {
if len(policyConfig.Inbound.Region.CountryExceptURLPatterns) > 0 {
this.Data["exceptURLPatterns"] = policyConfig.Inbound.Region.CountryExceptURLPatterns
}
if len(policyConfig.Inbound.Region.CountryOnlyURLPatterns) > 0 {
this.Data["onlyURLPatterns"] = policyConfig.Inbound.Region.CountryOnlyURLPatterns
}
} }
this.Data["countries"] = countryMaps
this.Show() this.Show()
} }
func (this *IndexAction) RunPost(params struct { func (this *IndexAction) RunPost(params struct {
FirewallPolicyId int64 FirewallPolicyId int64
CountryIds []int64 DenyCountryIds []int64
AllowCountryIds []int64
ExceptURLPatternsJSON []byte
OnlyURLPatternsJSON []byte
Must *actions.Must Must *actions.Must
}) { }) {
@@ -87,7 +114,30 @@ func (this *IndexAction) RunPost(params struct {
IsOn: true, 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{}
if len(params.ExceptURLPatternsJSON) > 0 {
err = json.Unmarshal(params.ExceptURLPatternsJSON, &exceptURLPatterns)
if err != nil {
this.Fail("校验例外URL参数失败" + err.Error())
return
}
}
policyConfig.Inbound.Region.CountryExceptURLPatterns = exceptURLPatterns
// 限制URL
var onlyURLPatterns = []*shared.URLPattern{}
if len(params.OnlyURLPatternsJSON) > 0 {
err = json.Unmarshal(params.OnlyURLPatternsJSON, &onlyURLPatterns)
if err != nil {
this.Fail("校验限制URL参数失败" + err.Error())
return
}
}
policyConfig.Inbound.Region.CountryOnlyURLPatterns = onlyURLPatterns
inboundJSON, err := json.Marshal(policyConfig.Inbound) inboundJSON, err := json.Marshal(policyConfig.Inbound)
if err != nil { if err != nil {

View File

@@ -8,6 +8,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/regionconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/regionconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
@@ -36,9 +37,12 @@ func (this *ProvincesAction) RunGet(params struct {
this.NotFound("firewallPolicy", params.FirewallPolicyId) this.NotFound("firewallPolicy", params.FirewallPolicyId)
return return
} }
var selectedProvinceIds = []int64{}
var deniedProvinceIds = []int64{}
var allowedProvinceIds = []int64{}
if policyConfig.Inbound != nil && policyConfig.Inbound.Region != nil { 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{ provincesResp, err := this.RPC().RegionProvinceRPC().FindAllRegionProvincesWithRegionCountryId(this.AdminContext(), &pb.FindAllRegionProvincesWithRegionCountryIdRequest{
@@ -48,22 +52,45 @@ func (this *ProvincesAction) RunGet(params struct {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
var provinceMaps = []maps.Map{} var deniedProvinceMaps = []maps.Map{}
var allowedProvinceMaps = []maps.Map{}
for _, province := range provincesResp.RegionProvinces { for _, province := range provincesResp.RegionProvinces {
provinceMaps = append(provinceMaps, maps.Map{ var provinceMap = maps.Map{
"id": province.Id, "id": province.Id,
"name": province.DisplayName, "name": province.DisplayName,
"isChecked": lists.ContainsInt64(selectedProvinceIds, province.Id), }
}) if lists.ContainsInt64(deniedProvinceIds, province.Id) {
deniedProvinceMaps = append(deniedProvinceMaps, provinceMap)
}
if lists.ContainsInt64(allowedProvinceIds, province.Id) {
allowedProvinceMaps = append(allowedProvinceMaps, provinceMap)
}
}
this.Data["deniedProvinces"] = deniedProvinceMaps
this.Data["allowedProvinces"] = allowedProvinceMaps
// except & only URL Patterns
this.Data["exceptURLPatterns"] = []*shared.URLPattern{}
this.Data["onlyURLPatterns"] = []*shared.URLPattern{}
if policyConfig.Inbound != nil && policyConfig.Inbound.Region != nil {
if len(policyConfig.Inbound.Region.ProvinceExceptURLPatterns) > 0 {
this.Data["exceptURLPatterns"] = policyConfig.Inbound.Region.ProvinceExceptURLPatterns
}
if len(policyConfig.Inbound.Region.ProvinceOnlyURLPatterns) > 0 {
this.Data["onlyURLPatterns"] = policyConfig.Inbound.Region.ProvinceOnlyURLPatterns
}
} }
this.Data["provinces"] = provinceMaps
this.Show() this.Show()
} }
func (this *ProvincesAction) RunPost(params struct { func (this *ProvincesAction) RunPost(params struct {
FirewallPolicyId int64 FirewallPolicyId int64
ProvinceIds []int64 DenyProvinceIds []int64
AllowProvinceIds []int64
ExceptURLPatternsJSON []byte
OnlyURLPatternsJSON []byte
Must *actions.Must Must *actions.Must
}) { }) {
@@ -88,7 +115,30 @@ func (this *ProvincesAction) RunPost(params struct {
IsOn: true, 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{}
if len(params.ExceptURLPatternsJSON) > 0 {
err = json.Unmarshal(params.ExceptURLPatternsJSON, &exceptURLPatterns)
if err != nil {
this.Fail("校验例外URL参数失败" + err.Error())
return
}
}
policyConfig.Inbound.Region.ProvinceExceptURLPatterns = exceptURLPatterns
// 限制URL
var onlyURLPatterns = []*shared.URLPattern{}
if len(params.OnlyURLPatternsJSON) > 0 {
err = json.Unmarshal(params.OnlyURLPatternsJSON, &onlyURLPatterns)
if err != nil {
this.Fail("校验限制URL参数失败" + err.Error())
return
}
}
policyConfig.Inbound.Region.ProvinceOnlyURLPatterns = onlyURLPatterns
inboundJSON, err := json.Marshal(policyConfig.Inbound) inboundJSON, err := json.Marshal(policyConfig.Inbound)
if err != nil { if err != nil {

View File

@@ -7,6 +7,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
@@ -41,9 +42,12 @@ func (this *CountriesAction) RunGet(params struct {
this.NotFound("firewallPolicy", params.FirewallPolicyId) this.NotFound("firewallPolicy", params.FirewallPolicyId)
return return
} }
selectedCountryIds := []int64{}
var deniedCountryIds = []int64{}
var allowedCountryIds = []int64{}
if policyConfig.Inbound != nil && policyConfig.Inbound.Region != nil { 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{}) countriesResp, err := this.RPC().RegionCountryRPC().FindAllRegionCountries(this.AdminContext(), &pb.FindAllRegionCountriesRequest{})
@@ -51,16 +55,35 @@ func (this *CountriesAction) RunGet(params struct {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
countryMaps := []maps.Map{} var deniesCountryMaps = []maps.Map{}
var allowedCountryMaps = []maps.Map{}
for _, country := range countriesResp.RegionCountries { for _, country := range countriesResp.RegionCountries {
countryMaps = append(countryMaps, maps.Map{ var countryMap = maps.Map{
"id": country.Id, "id": country.Id,
"name": country.DisplayName, "name": country.DisplayName,
"letter": strings.ToUpper(string(country.Pinyin[0][0])), "letter": strings.ToUpper(string(country.Pinyin[0][0])),
"isChecked": lists.ContainsInt64(selectedCountryIds, country.Id), }
}) if lists.ContainsInt64(deniedCountryIds, country.Id) {
deniesCountryMaps = append(deniesCountryMaps, countryMap)
}
if lists.ContainsInt64(allowedCountryIds, country.Id) {
allowedCountryMaps = append(allowedCountryMaps, countryMap)
}
}
this.Data["deniedCountries"] = deniesCountryMaps
this.Data["allowedCountries"] = allowedCountryMaps
// except & only URL Patterns
this.Data["exceptURLPatterns"] = []*shared.URLPattern{}
this.Data["onlyURLPatterns"] = []*shared.URLPattern{}
if policyConfig.Inbound != nil && policyConfig.Inbound.Region != nil {
if len(policyConfig.Inbound.Region.CountryExceptURLPatterns) > 0 {
this.Data["exceptURLPatterns"] = policyConfig.Inbound.Region.CountryExceptURLPatterns
}
if len(policyConfig.Inbound.Region.CountryOnlyURLPatterns) > 0 {
this.Data["onlyURLPatterns"] = policyConfig.Inbound.Region.CountryOnlyURLPatterns
}
} }
this.Data["countries"] = countryMaps
// WAF是否启用 // WAF是否启用
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId)
@@ -75,7 +98,11 @@ func (this *CountriesAction) RunGet(params struct {
func (this *CountriesAction) RunPost(params struct { func (this *CountriesAction) RunPost(params struct {
FirewallPolicyId int64 FirewallPolicyId int64
CountryIds []int64 DenyCountryIds []int64
AllowCountryIds []int64
ExceptURLPatternsJSON []byte
OnlyURLPatternsJSON []byte
Must *actions.Must Must *actions.Must
}) { }) {
@@ -100,7 +127,30 @@ func (this *CountriesAction) RunPost(params struct {
IsOn: true, 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{}
if len(params.ExceptURLPatternsJSON) > 0 {
err = json.Unmarshal(params.ExceptURLPatternsJSON, &exceptURLPatterns)
if err != nil {
this.Fail("校验例外URL参数失败" + err.Error())
return
}
}
policyConfig.Inbound.Region.CountryExceptURLPatterns = exceptURLPatterns
// 限制URL
var onlyURLPatterns = []*shared.URLPattern{}
if len(params.OnlyURLPatternsJSON) > 0 {
err = json.Unmarshal(params.OnlyURLPatternsJSON, &onlyURLPatterns)
if err != nil {
this.Fail("校验限制URL参数失败" + err.Error())
return
}
}
policyConfig.Inbound.Region.CountryOnlyURLPatterns = onlyURLPatterns
inboundJSON, err := json.Marshal(policyConfig.Inbound) inboundJSON, err := json.Marshal(policyConfig.Inbound)
if err != nil { if err != nil {

View File

@@ -7,6 +7,8 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" "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/actions"
"github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
@@ -39,27 +41,49 @@ func (this *ProvincesAction) RunGet(params struct {
this.NotFound("firewallPolicy", params.FirewallPolicyId) this.NotFound("firewallPolicy", params.FirewallPolicyId)
return return
} }
selectedProvinceIds := []int64{}
var deniedProvinceIds = []int64{}
var allowedProvinceIds = []int64{}
if policyConfig.Inbound != nil && policyConfig.Inbound.Region != nil { 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{ provincesResp, err := this.RPC().RegionProvinceRPC().FindAllRegionProvincesWithRegionCountryId(this.AdminContext(), &pb.FindAllRegionProvincesWithRegionCountryIdRequest{
RegionCountryId: int64(ChinaCountryId), RegionCountryId: regionconfigs.RegionChinaId,
}) })
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)
return return
} }
provinceMaps := []maps.Map{} var deniedProvinceMaps = []maps.Map{}
var allowedProvinceMaps = []maps.Map{}
for _, province := range provincesResp.RegionProvinces { for _, province := range provincesResp.RegionProvinces {
provinceMaps = append(provinceMaps, maps.Map{ var provinceMap = maps.Map{
"id": province.Id, "id": province.Id,
"name": province.DisplayName, "name": province.DisplayName,
"isChecked": lists.ContainsInt64(selectedProvinceIds, province.Id), }
}) if lists.ContainsInt64(deniedProvinceIds, province.Id) {
deniedProvinceMaps = append(deniedProvinceMaps, provinceMap)
}
if lists.ContainsInt64(allowedProvinceIds, province.Id) {
allowedProvinceMaps = append(allowedProvinceMaps, provinceMap)
}
}
this.Data["deniedProvinces"] = deniedProvinceMaps
this.Data["allowedProvinces"] = allowedProvinceMaps
// except & only URL Patterns
this.Data["exceptURLPatterns"] = []*shared.URLPattern{}
this.Data["onlyURLPatterns"] = []*shared.URLPattern{}
if policyConfig.Inbound != nil && policyConfig.Inbound.Region != nil {
if len(policyConfig.Inbound.Region.ProvinceExceptURLPatterns) > 0 {
this.Data["exceptURLPatterns"] = policyConfig.Inbound.Region.ProvinceExceptURLPatterns
}
if len(policyConfig.Inbound.Region.ProvinceOnlyURLPatterns) > 0 {
this.Data["onlyURLPatterns"] = policyConfig.Inbound.Region.ProvinceOnlyURLPatterns
}
} }
this.Data["provinces"] = provinceMaps
// WAF是否启用 // WAF是否启用
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId)
@@ -74,7 +98,11 @@ func (this *ProvincesAction) RunGet(params struct {
func (this *ProvincesAction) RunPost(params struct { func (this *ProvincesAction) RunPost(params struct {
FirewallPolicyId int64 FirewallPolicyId int64
ProvinceIds []int64 DenyProvinceIds []int64
AllowProvinceIds []int64
ExceptURLPatternsJSON []byte
OnlyURLPatternsJSON []byte
Must *actions.Must Must *actions.Must
}) { }) {
@@ -99,7 +127,30 @@ func (this *ProvincesAction) RunPost(params struct {
IsOn: true, 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{}
if len(params.ExceptURLPatternsJSON) > 0 {
err = json.Unmarshal(params.ExceptURLPatternsJSON, &exceptURLPatterns)
if err != nil {
this.Fail("校验例外URL参数失败" + err.Error())
return
}
}
policyConfig.Inbound.Region.ProvinceExceptURLPatterns = exceptURLPatterns
// 限制URL
var onlyURLPatterns = []*shared.URLPattern{}
if len(params.OnlyURLPatternsJSON) > 0 {
err = json.Unmarshal(params.OnlyURLPatternsJSON, &onlyURLPatterns)
if err != nil {
this.Fail("校验限制URL参数失败" + err.Error())
return
}
}
policyConfig.Inbound.Region.ProvinceOnlyURLPatterns = onlyURLPatterns
inboundJSON, err := json.Marshal(policyConfig.Inbound) inboundJSON, err := json.Marshal(policyConfig.Inbound)
if err != nil { if err != nil {

View File

@@ -41,6 +41,7 @@ func (this *ProvincesAction) RunGet(params struct {
this.NotFound("firewallPolicy", params.FirewallPolicyId) this.NotFound("firewallPolicy", params.FirewallPolicyId)
return return
} }
var deniedProvinceIds = []int64{} var deniedProvinceIds = []int64{}
var allowedProvinceIds = []int64{} var allowedProvinceIds = []int64{}
if policyConfig.Inbound != nil && policyConfig.Inbound.Region != nil { if policyConfig.Inbound != nil && policyConfig.Inbound.Region != nil {

View File

@@ -5,6 +5,8 @@ package ui
import ( import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/regionconfigs"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
"strings" "strings"
) )
@@ -21,6 +23,10 @@ func (this *CountryOptionsAction) RunPost(params struct{}) {
} }
var countryMaps = []maps.Map{} var countryMaps = []maps.Map{}
for _, country := range countriesResp.RegionCountries { for _, country := range countriesResp.RegionCountries {
if lists.ContainsInt64(regionconfigs.FindAllGreaterChinaSubRegionIds(), country.Id) {
continue
}
if country.Codes == nil { if country.Codes == nil {
country.Codes = []string{} country.Codes = []string{}
} }

View File

@@ -1,51 +1,39 @@
{$layout} {$layout}
{$template "../waf_menu"} {$template "../waf_menu"}
{$template "menu"} {$template "menu"}
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success"> <form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="firewallPolicyId" :value="firewallPolicyId"/> <input type="hidden" name="firewallPolicyId" :value="firewallPolicyId"/>
<table class="ui table selectable definition"> <input type="hidden" name="exceptURLPatternsJSON" :value="JSON.stringify(exceptURLPatterns)"/>
<tr> <input type="hidden" name="onlyURLPatternsJSON" :value="JSON.stringify(onlyURLPatterns)"/>
<td class="title">已封禁</td> <table class="ui table selectable definition">
<td> <tr>
<span v-if="countSelectedCountries == 0" class="disabled">暂时没有选择封禁区域</span> <td class="title">仅允许的区域</td>
<div class="ui label tiny basic" v-for="country in countries" v-if="country.isChecked" style="margin-bottom: 0.5em"> <td>
<input type="hidden" name="countryIds" :value="country.id"/> <http-firewall-region-selector :v-countries="allowedCountries" :v-type="'allow'" @change="changeAllowedCountries"></http-firewall-region-selector>
({{country.letter}}){{country.name}} <a href="" @click.prevent="deselectCountry(country)" title="取消封禁"><i class="icon remove"></i></a> </td>
</div> </tr>
</td> <tr>
</tr> <td class="title">仅封禁的区域</td>
<tr> <td>
<td>选择封禁区域</td> <p class="comment" v-if="allowedCountries.length > 0">由于你已设置"仅允许的区域",所以不需要再设置封禁区域</p>
<td> <http-firewall-region-selector :v-countries="deniedCountries" :v-type="'deny'" v-show="allowedCountries.length == 0"></http-firewall-region-selector>
<more-options-indicator>选择区域</more-options-indicator> </td>
</tr>
<div class="ui menu tabular tiny region-letter-group" v-show="moreOptionsVisible"> <tr>
<a href="" v-for="group in letterGroups" class="item" :class="{active: group == selectedGroup}" @click.prevent="selectGroup(group)">{{group}}</a> <td colspan="2"><more-options-indicator></more-options-indicator></td>
<div class="item right"> </tr>
<div class="ui checkbox" @click.prevent="checkAll"> <tbody v-show="moreOptionsVisible">
<input type="checkbox" v-model="isCheckingAll"/> <tr>
<label>全选</label> <td>例外URL &nbsp;<tip-icon content="对这些URL将不做任何限制。"></tip-icon></td>
</div> <td><url-patterns-box v-model="exceptURLPatterns"></url-patterns-box></td>
</div> </tr>
</div> <tr>
<div v-for="group in letterGroups" v-show="moreOptionsVisible"> <td>限制URL &nbsp;<tip-icon content="只对这些URL做限制。"></tip-icon></td>
<div v-for="letter in group" v-if="letterCountries[letter] != null && group == selectedGroup" class="country-group"> <td><url-patterns-box v-model="onlyURLPatterns"></url-patterns-box></td>
<h4>{{letter}}</h4> </tr>
<div class="country-list"> </tbody>
<div class="item" v-for="country in letterCountries[letter]"> </table>
<div class="ui checkbox" @click.prevent="selectCountry(country)"> <submit-btn></submit-btn>
<input type="checkbox" v-model="country.isChecked"/> </form>
<label>{{country.name}}</label>
</div>
</div>
</div>
<div class="clear"></div>
</div>
</div>
</td>
</tr>
</table>
<submit-btn></submit-btn>
</form>

View File

@@ -1,54 +1,11 @@
Tea.context(function () { 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 () { this.success = function () {
teaweb.success("保存成功", function () { teaweb.success("保存成功", function () {
teaweb.reload() teaweb.reload()
}) })
} }
this.change = function () { this.changeAllowedCountries = function (event) {
this.countSelectedCountries = this.countries.$count(function (k, country) { this.allowedCountries = event.countries
return country.isChecked
})
} }
}) })

View File

@@ -5,42 +5,35 @@
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success"> <form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="firewallPolicyId" :value="firewallPolicyId"/> <input type="hidden" name="firewallPolicyId" :value="firewallPolicyId"/>
<input type="hidden" name="exceptURLPatternsJSON" :value="JSON.stringify(exceptURLPatterns)"/>
<input type="hidden" name="onlyURLPatternsJSON" :value="JSON.stringify(onlyURLPatterns)"/>
<table class="ui table selectable definition"> <table class="ui table selectable definition">
<tr> <tr>
<td class="title">已封禁</td> <td class="title">仅允许的省份</td>
<td> <td>
<span v-if="countSelectedProvinces == 0" class="disabled">暂时没有选择封禁省份。</span> <http-firewall-province-selector :v-provinces="allowedProvinces" :v-type="'allow'" @change="changeAllowedProvinces"></http-firewall-province-selector>
<div class="ui label tiny basic" v-for="province in provinces" v-if="province.isChecked" style="margin-bottom: 0.5em"> </td>
<input type="hidden" name="provinceIds" :value="province.id"/> </tr>
{{province.name}} <a href="" @click.prevent="deselectProvince(province)" title="取消封禁"><i class="icon remove"></i></a> <tr>
</div> <td class="title">仅封禁的省份</td>
</td> <td>
</tr> <p class="comment" v-if="allowedProvinces.length > 0">由于你已设置"仅允许的省份",所以不需要再设置封禁省份。</p>
<tr> <http-firewall-province-selector :v-provinces="deniedProvinces" :v-type="'deny'" v-show="allowedProvinces.length == 0"></http-firewall-province-selector>
<td>选择封禁区域</td> </td>
<td> </tr>
<tr>
<first-menu> <td colspan="2"><more-options-indicator></more-options-indicator></td>
<menu-item><more-options-indicator>选择省份/自治区</more-options-indicator></menu-item> </tr>
<div class="item right" v-show="moreOptionsVisible"> <tbody v-show="moreOptionsVisible">
<div class="ui checkbox" @click.prevent="checkAll"> <tr>
<input type="checkbox" v-model="isCheckingAll"/> <td>例外URL &nbsp;<tip-icon content="对这些URL将不做任何限制。"></tip-icon></td>
<label>全选</label> <td><url-patterns-box v-model="exceptURLPatterns"></url-patterns-box></td>
</div> </tr>
</div> <tr>
</first-menu> <td>限制URL &nbsp;<tip-icon content="只对这些URL做限制。"></tip-icon></td>
<td><url-patterns-box v-model="onlyURLPatterns"></url-patterns-box></td>
<div class="province-list" v-show="moreOptionsVisible" style="margin-top:0.5em"> </tr>
<div class="item" v-for="province in provinces"> </tbody>
<div class="ui checkbox" @click.prevent="selectProvince(province)">
<input type="checkbox" v-model="province.isChecked"/>
<label>{{province.name}}</label>
</div>
</div>
</div>
<div class="clear"></div>
</td>
</tr>
</table> </table>
<submit-btn></submit-btn> <submit-btn></submit-btn>
</form> </form>

View File

@@ -1,30 +1,4 @@
Tea.context(function () { 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 () { this.success = function () {
teaweb.success("保存成功", function () { teaweb.success("保存成功", function () {
teaweb.reload() teaweb.reload()
@@ -32,9 +6,7 @@ Tea.context(function () {
} }
this.change = function () { this.changeAllowedProvinces = function (event) {
this.countSelectedProvinces = this.provinces.$count(function (k, province) { this.allowedProvinces = event.provinces
return province.isChecked
})
} }
}) })

View File

@@ -11,47 +11,35 @@
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success"> <form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="firewallPolicyId" :value="firewallPolicyId"/> <input type="hidden" name="firewallPolicyId" :value="firewallPolicyId"/>
<input type="hidden" name="exceptURLPatternsJSON" :value="JSON.stringify(exceptURLPatterns)"/>
<input type="hidden" name="onlyURLPatternsJSON" :value="JSON.stringify(onlyURLPatterns)"/>
<table class="ui table selectable definition"> <table class="ui table selectable definition">
<tr> <tr>
<td class="title">已封禁</td> <td class="title">仅允许的区域</td>
<td> <td>
<span v-if="countSelectedCountries == 0" class="disabled">暂时没有选择封禁区域。</span> <http-firewall-region-selector :v-countries="allowedCountries" :v-type="'allow'" @change="changeAllowedCountries"></http-firewall-region-selector>
<div class="ui label tiny basic" v-for="country in countries" v-if="country.isChecked" style="margin-bottom: 0.5em"> </td>
<input type="hidden" name="countryIds" :value="country.id"/> </tr>
({{country.letter}}){{country.name}} <a href="" @click.prevent="deselectCountry(country)" title="取消封禁"><i class="icon remove"></i></a> <tr>
</div> <td class="title">仅封禁的区域</td>
</td> <td>
</tr> <p class="comment" v-if="allowedCountries.length > 0">由于你已设置"仅允许的区域",所以不需要再设置封禁区域。</p>
<tr> <http-firewall-region-selector :v-countries="deniedCountries" :v-type="'deny'" v-show="allowedCountries.length == 0"></http-firewall-region-selector>
<td>选择封禁区域</td> </td>
<td> </tr>
<more-options-indicator>选择区域</more-options-indicator> <tr>
<td colspan="2"><more-options-indicator></more-options-indicator></td>
<div class="ui menu tabular tiny region-letter-group" v-show="moreOptionsVisible"> </tr>
<a href="" v-for="group in letterGroups" class="item" :class="{active: group == selectedGroup}" @click.prevent="selectGroup(group)">{{group}}</a> <tbody v-show="moreOptionsVisible">
<div class="item right"> <tr>
<div class="ui checkbox" @click.prevent="checkAll"> <td>例外URL &nbsp;<tip-icon content="对这些URL将不做任何限制。"></tip-icon></td>
<input type="checkbox" v-model="isCheckingAll"/> <td><url-patterns-box v-model="exceptURLPatterns"></url-patterns-box></td>
<label>全选</label> </tr>
</div> <tr>
</div> <td>限制URL &nbsp;<tip-icon content="只对这些URL做限制。"></tip-icon></td>
</div> <td><url-patterns-box v-model="onlyURLPatterns"></url-patterns-box></td>
<div v-for="group in letterGroups" v-show="moreOptionsVisible"> </tr>
<div v-for="letter in group" v-if="letterCountries[letter] != null && group == selectedGroup" class="country-group"> </tbody>
<h4>{{letter}}</h4>
<div class="country-list">
<div class="item" v-for="country in letterCountries[letter]">
<div class="ui checkbox" @click.prevent="selectCountry(country)">
<input type="checkbox" v-model="country.isChecked"/>
<label>{{country.name}}</label>
</div>
</div>
</div>
<div class="clear"></div>
</div>
</div>
</td>
</tr>
</table> </table>
<submit-btn></submit-btn> <submit-btn></submit-btn>
</form> </form>

View File

@@ -1,54 +1,11 @@
Tea.context(function () { 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 () { this.success = function () {
teaweb.success("保存成功", function () { teaweb.success("保存成功", function () {
teaweb.reload() teaweb.reload()
}) })
} }
this.change = function () { this.changeAllowedCountries = function (event) {
this.countSelectedCountries = this.countries.$count(function (k, country) { this.allowedCountries = event.countries
return country.isChecked
})
} }
}) })

View File

@@ -11,42 +11,35 @@
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success"> <form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="firewallPolicyId" :value="firewallPolicyId"/> <input type="hidden" name="firewallPolicyId" :value="firewallPolicyId"/>
<input type="hidden" name="exceptURLPatternsJSON" :value="JSON.stringify(exceptURLPatterns)"/>
<input type="hidden" name="onlyURLPatternsJSON" :value="JSON.stringify(onlyURLPatterns)"/>
<table class="ui table selectable definition"> <table class="ui table selectable definition">
<tr> <tr>
<td class="title">已封禁</td> <td class="title">仅允许的省份</td>
<td> <td>
<span v-if="countSelectedProvinces == 0" class="disabled">暂时没有选择封禁省份。</span> <http-firewall-province-selector :v-provinces="allowedProvinces" :v-type="'allow'" @change="changeAllowedProvinces"></http-firewall-province-selector>
<div class="ui label tiny basic" v-for="province in provinces" v-if="province.isChecked" style="margin-bottom: 0.5em"> </td>
<input type="hidden" name="provinceIds" :value="province.id"/> </tr>
{{province.name}} <a href="" @click.prevent="deselectProvince(province)" title="取消封禁"><i class="icon remove"></i></a> <tr>
</div> <td class="title">仅封禁的省份</td>
</td> <td>
</tr> <p class="comment" v-if="allowedProvinces.length > 0">由于你已设置"仅允许的省份",所以不需要再设置封禁省份。</p>
<tr> <http-firewall-province-selector :v-provinces="deniedProvinces" :v-type="'deny'" v-show="allowedProvinces.length == 0"></http-firewall-province-selector>
<td>选择封禁区域</td> </td>
<td> </tr>
<tr>
<first-menu> <td colspan="2"><more-options-indicator></more-options-indicator></td>
<menu-item><more-options-indicator>选择省份/自治区</more-options-indicator></menu-item> </tr>
<div class="item right" v-show="moreOptionsVisible"> <tbody v-show="moreOptionsVisible">
<div class="ui checkbox" @click.prevent="checkAll"> <tr>
<input type="checkbox" v-model="isCheckingAll"/> <td>例外URL &nbsp;<tip-icon content="对这些URL将不做任何限制。"></tip-icon></td>
<label>全选</label> <td><url-patterns-box v-model="exceptURLPatterns"></url-patterns-box></td>
</div> </tr>
</div> <tr>
</first-menu> <td>限制URL &nbsp;<tip-icon content="只对这些URL做限制。"></tip-icon></td>
<td><url-patterns-box v-model="onlyURLPatterns"></url-patterns-box></td>
<div class="province-list" v-show="moreOptionsVisible" style="margin-top:0.5em"> </tr>
<div class="item" v-for="province in provinces"> </tbody>
<div class="ui checkbox" @click.prevent="selectProvince(province)">
<input type="checkbox" v-model="province.isChecked"/>
<label>{{province.name}}</label>
</div>
</div>
</div>
<div class="clear"></div>
</td>
</tr>
</table> </table>
<submit-btn></submit-btn> <submit-btn></submit-btn>
</form> </form>

View File

@@ -1,40 +1,11 @@
Tea.context(function () { 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 () { this.success = function () {
teaweb.success("保存成功", function () { teaweb.success("保存成功", function () {
teaweb.reload() teaweb.reload()
}) })
} }
this.changeAllowedProvinces = function (event) {
this.change = function () { this.allowedProvinces = event.provinces
this.countSelectedProvinces = this.provinces.$count(function (k, province) {
return province.isChecked
})
} }
}) })