单个服务里也增加国家/地区、省份封禁

This commit is contained in:
刘祥超
2021-02-02 16:23:23 +08:00
parent a0635a97d5
commit 33c9cd0819
10 changed files with 210 additions and 11 deletions

View File

@@ -17,8 +17,8 @@ func init() {
GetPost("", new(IndexAction)).
Get("/ipadmin/allowList", new(ipadmin.AllowListAction)).
Get("/ipadmin/denyList", new(ipadmin.DenyListAction)).
//GetPost("/ipadmin", new(ipadmin.IndexAction)).
//GetPost("/ipadmin/provinces", new(ipadmin.ProvincesAction)).
GetPost("/ipadmin/countries", new(ipadmin.CountriesAction)).
GetPost("/ipadmin/provinces", new(ipadmin.ProvincesAction)).
GetPost("/ipadmin/createIPPopup", new(ipadmin.CreateIPPopupAction)).
GetPost("/ipadmin/updateIPPopup", new(ipadmin.UpdateIPPopupAction)).
Post("/ipadmin/deleteIP", new(ipadmin.DeleteIPAction)).

View File

@@ -13,17 +13,22 @@ import (
"strings"
)
type IndexAction struct {
type CountriesAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "ipadmin")
func (this *CountriesAction) Init() {
this.Nav("", "setting", "country")
this.SecondMenu("waf")
}
func (this *IndexAction) RunGet(params struct {
func (this *CountriesAction) RunGet(params struct {
FirewallPolicyId int64
ServerId int64
}) {
this.Data["featureIsOn"] = true
this.Data["firewallPolicyId"] = params.FirewallPolicyId
this.Data["subMenuItem"] = "region"
// 当前选中的地区
@@ -57,10 +62,18 @@ func (this *IndexAction) RunGet(params struct {
}
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 *IndexAction) RunPost(params struct {
func (this *CountriesAction) RunPost(params struct {
FirewallPolicyId int64
CountryIds []int64

View File

@@ -19,12 +19,16 @@ type ProvincesAction struct {
}
func (this *ProvincesAction) Init() {
this.Nav("", "", "ipadmin")
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"
// 当前选中的省份
@@ -59,6 +63,14 @@ func (this *ProvincesAction) RunGet(params struct {
}
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()
}

View File

@@ -2,6 +2,8 @@
<menu-item :href="'/servers/server/settings/waf?serverId=' + serverId" code="index">设置</menu-item>
<menu-item :href="'/servers/server/settings/waf/groups?serverId=' + serverId + '&type=inbound&firewallPolicyId='+firewallPolicyId" code="inbound">入站规则</menu-item>
<menu-item :href="'/servers/server/settings/waf/groups?serverId=' + serverId + '&type=outbound&firewallPolicyId='+firewallPolicyId" code="outbound">出站规则</menu-item>
<menu-item :href="'/servers/server/settings/waf/ipadmin/countries?serverId=' + serverId + '&firewallPolicyId='+firewallPolicyId" code="country">国家/地区封禁</menu-item>
<menu-item :href="'/servers/server/settings/waf/ipadmin/provinces?serverId=' + serverId + '&firewallPolicyId='+firewallPolicyId" code="province">省份封禁</menu-item>
<menu-item :href="'/servers/server/settings/waf/ipadmin/allowList?serverId=' + serverId + '&firewallPolicyId='+firewallPolicyId" code="allowList">白名单</menu-item>
<menu-item :href="'/servers/server/settings/waf/ipadmin/denyList?serverId=' + serverId + '&firewallPolicyId='+firewallPolicyId" code="denyList">黑名单</menu-item>
</first-menu>

View 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=countries.css.map */

View File

@@ -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"}

View File

@@ -0,0 +1,59 @@
{$layout}
{$template "/left_menu"}
<div class="right-box">
{$template "../menu"}
<div class="ui message warning" v-if="!featureIsOn">尚未为当前用户开通此功能。</div>
{$ if .featureIsOn}
<p class="ui message warning" v-if="!wafIsOn">当前WAF未启用设置将在<a :href="'/servers/server/settings/waf?serverId=' + serverId">[启用]</a>后生效。</p>
<form method="post" 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>
<span v-if="countSelectedCountries == 0" class="disabled">暂时没有选择封禁区域。</span>
<div class="ui label tiny basic" 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>
<more-options-indicator>选择区域</more-options-indicator>
<div class="ui menu tabular tiny region-letter-group" v-show="moreOptionsVisible">
<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" v-show="moreOptionsVisible">
<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>
{$end}
</div>

View File

@@ -0,0 +1,66 @@
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
})
}
/**
* 添加IP名单菜单
*/
this.createIP = function (type) {
teaweb.popup("/servers/components/waf/ipadmin/createIPPopup?firewallPolicyId=" + this.firewallPolicyId + '&type=' + type, {
height: "23em",
callback: function () {
window.location = "/servers/components/waf/ipadmin/lists?firewallPolicyId=" + this.firewallPolicyId + "&type=" + type
}
})
}
})

View 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;
}

View File

@@ -1,7 +1,13 @@
{$layout}
{$template "/left_menu"}
{$template "../waf_menu"}
{$template "menu"}
<div class="right-box">
{$template "../menu"}
<div class="ui message warning" v-if="!featureIsOn">尚未为当前用户开通此功能。</div>
{$ if .featureIsOn}
<p class="ui message warning" v-if="!wafIsOn">当前WAF未启用设置将在<a :href="'/servers/server/settings/waf?serverId=' + serverId">[启用]</a>后生效。</p>
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="firewallPolicyId" :value="firewallPolicyId"/>
@@ -43,4 +49,6 @@
</tr>
</table>
<submit-btn></submit-btn>
</form>
</form>
{$end}
</div>