mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-08 07:50:28 +08:00
增加国家/地区封禁管理
This commit is contained in:
@@ -184,6 +184,14 @@ func (this *RPCClient) FileChunkRPC() pb.FileChunkServiceClient {
|
|||||||
return pb.NewFileChunkServiceClient(this.pickConn())
|
return pb.NewFileChunkServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) RegionCountryRPC() pb.RegionCountryServiceClient {
|
||||||
|
return pb.NewRegionCountryServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) RegionProvinceRPC() pb.RegionProvinceServiceClient {
|
||||||
|
return pb.NewRegionProvinceServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
// 构造Admin上下文
|
// 构造Admin上下文
|
||||||
func (this *RPCClient) Context(adminId int64) context.Context {
|
func (this *RPCClient) Context(adminId int64) context.Context {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package waf
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/componentutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/componentutils"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/waf/ipadmin"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||||
"github.com/iwind/TeaGo"
|
"github.com/iwind/TeaGo"
|
||||||
)
|
)
|
||||||
@@ -26,7 +27,6 @@ func init() {
|
|||||||
GetPost("/import", new(ImportAction)).
|
GetPost("/import", new(ImportAction)).
|
||||||
Post("/updateGroupOn", new(UpdateGroupOnAction)).
|
Post("/updateGroupOn", new(UpdateGroupOnAction)).
|
||||||
Post("/deleteGroup", new(DeleteGroupAction)).
|
Post("/deleteGroup", new(DeleteGroupAction)).
|
||||||
GetPost("/ipadmin", new(IpadminAction)).
|
|
||||||
GetPost("/createGroupPopup", new(CreateGroupPopupAction)).
|
GetPost("/createGroupPopup", new(CreateGroupPopupAction)).
|
||||||
Post("/sortGroups", new(SortGroupsAction)).
|
Post("/sortGroups", new(SortGroupsAction)).
|
||||||
GetPost("/updateGroupPopup", new(UpdateGroupPopupAction)).
|
GetPost("/updateGroupPopup", new(UpdateGroupPopupAction)).
|
||||||
@@ -36,6 +36,12 @@ func init() {
|
|||||||
Post("/updateSetOn", new(UpdateSetOnAction)).
|
Post("/updateSetOn", new(UpdateSetOnAction)).
|
||||||
Post("/deleteSet", new(DeleteSetAction)).
|
Post("/deleteSet", new(DeleteSetAction)).
|
||||||
GetPost("/updateSetPopup", new(UpdateSetPopupAction)).
|
GetPost("/updateSetPopup", new(UpdateSetPopupAction)).
|
||||||
|
|
||||||
|
// IP管理
|
||||||
|
GetPost("/ipadmin", new(ipadmin.IndexAction)).
|
||||||
|
GetPost("/ipadmin/provinces", new(ipadmin.ProvincesAction)).
|
||||||
|
Get("/ipadmin/lists", new(ipadmin.ListsAction)).
|
||||||
|
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package waf
|
|
||||||
|
|
||||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
|
|
||||||
type IpadminAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IpadminAction) Init() {
|
|
||||||
this.Nav("", "", "ipadmin")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IpadminAction) RunGet(params struct{}) {
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
package ipadmin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/models"
|
||||||
|
"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 IndexAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) Init() {
|
||||||
|
this.Nav("", "", "ipadmin")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunGet(params struct {
|
||||||
|
FirewallPolicyId int64
|
||||||
|
}) {
|
||||||
|
this.Data["subMenuItem"] = "region"
|
||||||
|
|
||||||
|
// 当前选中的地区
|
||||||
|
policyConfig, err := models.SharedHTTPFirewallPolicyDAO.FindEnabledPolicyConfig(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
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunPost(params struct {
|
||||||
|
FirewallPolicyId int64
|
||||||
|
CountryIds []int64
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
}) {
|
||||||
|
policyConfig, err := models.SharedHTTPFirewallPolicyDAO.FindEnabledPolicyConfig(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{
|
||||||
|
FirewallPolicyId: params.FirewallPolicyId,
|
||||||
|
InboundJSON: inboundJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package ipadmin
|
||||||
|
|
||||||
|
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
|
||||||
|
type ListsAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ListsAction) Init() {
|
||||||
|
this.Nav("", "", "ipadmin")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ListsAction) RunGet(params struct{}) {
|
||||||
|
this.Data["subMenuItem"] = "list"
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package ipadmin
|
||||||
|
|
||||||
|
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
|
||||||
|
type ProvincesAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ProvincesAction) Init() {
|
||||||
|
this.Nav("", "", "ipadmin")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ProvincesAction) RunGet(params struct{}) {
|
||||||
|
this.Data["subMenuItem"] = "province"
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
{$layout}
|
|
||||||
{$template "/left_menu"}
|
|
||||||
|
|
||||||
<div class="right-box">
|
|
||||||
{$template "waf_menu"}
|
|
||||||
|
|
||||||
<p class="ui message">此功能暂未开放,敬请期待。</p>
|
|
||||||
</div>
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<second-menu style="margin-top:-1em">
|
||||||
|
<menu-item :href="'/servers/components/waf/ipadmin?firewallPolicyId=' + firewallPolicyId" :active="subMenuItem == 'region'">国家/地区封禁</menu-item>
|
||||||
|
<menu-item :href="'/servers/components/waf/ipadmin/provinces?firewallPolicyId=' + firewallPolicyId" :active="subMenuItem == 'province'">省份封禁</menu-item>
|
||||||
|
<menu-item :href="'/servers/components/waf/ipadmin/lists?firewallPolicyId=' + firewallPolicyId" :active="subMenuItem == 'list'">IP名单</menu-item>
|
||||||
|
</second-menu>
|
||||||
16
web/views/@default/servers/components/waf/ipadmin/index.css
Normal file
16
web/views/@default/servers/components/waf/ipadmin/index.css
Normal file
@@ -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=index.css.map */
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":["index.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":"index.css"}
|
||||||
51
web/views/@default/servers/components/waf/ipadmin/index.html
Normal file
51
web/views/@default/servers/components/waf/ipadmin/index.html
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
{$layout}
|
||||||
|
{$template "/left_menu"}
|
||||||
|
|
||||||
|
<div class="right-box">
|
||||||
|
{$template "../waf_menu"}
|
||||||
|
{$template "menu"}
|
||||||
|
|
||||||
|
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||||
|
<input type="hidden" name="firewallPolicyId" :value="firewallPolicyId"/>
|
||||||
|
<table class="ui table selectable definition">
|
||||||
|
<tr>
|
||||||
|
<td class="title">已封禁</td>
|
||||||
|
<td>
|
||||||
|
<div class="ui label tiny" v-for="country in countries" v-if="country.isChecked" style="margin-bottom: 0.5em">
|
||||||
|
<input type="hidden" name="countryIds" :value="country.id"/>
|
||||||
|
({{country.letter}}){{country.name}} <a href="" @click.prevent="deselectCountry(country)" title="取消封禁"><i class="icon remove"></i></a>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>选择封禁区域</td>
|
||||||
|
<td>
|
||||||
|
<div class="ui menu tabular tiny region-letter-group">
|
||||||
|
<a href="" v-for="group in letterGroups" class="item" :class="{active: group == selectedGroup}" @click.prevent="selectGroup(group)">{{group}}</a>
|
||||||
|
<div class="item right">
|
||||||
|
<div class="ui checkbox" @click.prevent="checkAll">
|
||||||
|
<input type="checkbox" v-model="isCheckingAll"/>
|
||||||
|
<label>全选</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-for="group in letterGroups">
|
||||||
|
<div v-for="letter in group" v-if="letterCountries[letter] != null && group == selectedGroup" class="country-group">
|
||||||
|
<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>
|
||||||
|
<submit-btn></submit-btn>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
40
web/views/@default/servers/components/waf/ipadmin/index.js
Normal file
40
web/views/@default/servers/components/waf/ipadmin/index.js
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
Tea.context(function () {
|
||||||
|
this.letterGroups = [
|
||||||
|
"ABC", "DEF", "GHI", "JKL", "MNO", "PQR", "STU", "VWX", "YZ"
|
||||||
|
];
|
||||||
|
this.selectedGroup = "ABC"
|
||||||
|
this.selectedCountries = []
|
||||||
|
this.letterCountries = {}
|
||||||
|
let that = this
|
||||||
|
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.deselectCountry = function (country) {
|
||||||
|
country.isChecked = false
|
||||||
|
}
|
||||||
|
|
||||||
|
this.checkAll = function () {
|
||||||
|
this.isCheckingAll = !this.isCheckingAll
|
||||||
|
|
||||||
|
this.countries.forEach(function (country) {
|
||||||
|
country.isChecked = that.isCheckingAll
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
this.success = function () {
|
||||||
|
teaweb.successToast("保存成功")
|
||||||
|
}
|
||||||
|
})
|
||||||
22
web/views/@default/servers/components/waf/ipadmin/index.less
Normal file
22
web/views/@default/servers/components/waf/ipadmin/index.less
Normal file
@@ -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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{$layout}
|
||||||
|
{$template "/left_menu"}
|
||||||
|
|
||||||
|
<div class="right-box">
|
||||||
|
{$template "../waf_menu"}
|
||||||
|
{$template "menu"}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{$layout}
|
||||||
|
{$template "/left_menu"}
|
||||||
|
|
||||||
|
<div class="right-box">
|
||||||
|
{$template "../waf_menu"}
|
||||||
|
{$template "menu"}
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user