diff --git a/internal/web/actions/default/servers/components/waf/init.go b/internal/web/actions/default/servers/components/waf/init.go index 08d435d9..6848024d 100644 --- a/internal/web/actions/default/servers/components/waf/init.go +++ b/internal/web/actions/default/servers/components/waf/init.go @@ -48,6 +48,7 @@ func init() { GetPost("/ipadmin/createIPPopup", new(ipadmin.CreateIPPopupAction)). GetPost("/ipadmin/updateIPPopup", new(ipadmin.UpdateIPPopupAction)). Post("/ipadmin/deleteIP", new(ipadmin.DeleteIPAction)). + GetPost("/ipadmin/test", new(ipadmin.TestAction)). EndAll() }) diff --git a/internal/web/actions/default/servers/components/waf/ipadmin/test.go b/internal/web/actions/default/servers/components/waf/ipadmin/test.go new file mode 100644 index 00000000..61b4cef5 --- /dev/null +++ b/internal/web/actions/default/servers/components/waf/ipadmin/test.go @@ -0,0 +1,85 @@ +package ipadmin + +import ( + "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" + timeutil "github.com/iwind/TeaGo/utils/time" +) + +type TestAction struct { + actionutils.ParentAction +} + +func (this *TestAction) Init() { + this.Nav("", "", "ipadmin") +} + +func (this *TestAction) RunGet(params struct { + FirewallPolicyId int64 +}) { + this.Data["subMenuItem"] = "test" + + 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, + } + } + + 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/server/settings/waf/init.go b/internal/web/actions/default/servers/server/settings/waf/init.go index e53abf2e..667073ce 100644 --- a/internal/web/actions/default/servers/server/settings/waf/init.go +++ b/internal/web/actions/default/servers/server/settings/waf/init.go @@ -22,6 +22,7 @@ func init() { GetPost("/ipadmin/createIPPopup", new(ipadmin.CreateIPPopupAction)). GetPost("/ipadmin/updateIPPopup", new(ipadmin.UpdateIPPopupAction)). Post("/ipadmin/deleteIP", new(ipadmin.DeleteIPAction)). + GetPost("/ipadmin/test", new(ipadmin.TestAction)). // 规则相关 Get("/groups", new(GroupsAction)). diff --git a/internal/web/actions/default/servers/server/settings/waf/ipadmin/test.go b/internal/web/actions/default/servers/server/settings/waf/ipadmin/test.go new file mode 100644 index 00000000..1e7f4b15 --- /dev/null +++ b/internal/web/actions/default/servers/server/settings/waf/ipadmin/test.go @@ -0,0 +1,98 @@ +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/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, + } + } + + 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/web/public/js/components/iplist/ip-item-text.js b/web/public/js/components/iplist/ip-item-text.js new file mode 100644 index 00000000..759066a4 --- /dev/null +++ b/web/public/js/components/iplist/ip-item-text.js @@ -0,0 +1,11 @@ +Vue.component("ip-item-text", { + props: ["v-item"], + template: ` + * + + {{vItem.ipFrom}} + - {{vItem.ipTo}} + + {{vItem.ipFrom}} +` +}) \ No newline at end of file diff --git a/web/views/@default/servers/components/waf/ipadmin/@menu.html b/web/views/@default/servers/components/waf/ipadmin/@menu.html index 1a80b3d9..6c50ae16 100644 --- a/web/views/@default/servers/components/waf/ipadmin/@menu.html +++ b/web/views/@default/servers/components/waf/ipadmin/@menu.html @@ -1,10 +1,12 @@ 国家/地区封禁 省份封禁 - | + | 白名单 [添加IP] - | + | 黑名单 [添加IP] + | + IP检查 \ No newline at end of file diff --git a/web/views/@default/servers/components/waf/ipadmin/test.html b/web/views/@default/servers/components/waf/ipadmin/test.html new file mode 100644 index 00000000..355870e8 --- /dev/null +++ b/web/views/@default/servers/components/waf/ipadmin/test.html @@ -0,0 +1,48 @@ +{$layout} + +{$template "../waf_menu"} +{$template "menu"} + + +
+ + + + + + + + + + +
IP * + +

要检查的IP

+
检查结果 +
+
+ {{result.error}} +
+
+
+
+ 在白名单中 +
+
+ 在黑名单中 +
+
+
+ 在省份封禁中 "{{result.province.name}}" +
+
+ 在国家/地区封禁中 "{{result.country.name}}" +
+
+
+ 没有找到和{{ip}}匹配的配置。 +
+
+
+ 检查IP状态 +
diff --git a/web/views/@default/servers/components/waf/ipadmin/test.js b/web/views/@default/servers/components/waf/ipadmin/test.js new file mode 100644 index 00000000..67de57b9 --- /dev/null +++ b/web/views/@default/servers/components/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 (itemId) { + teaweb.popup(Tea.url(".updateIPPopup?firewallPolicyId=" + this.firewallPolicyId, {itemId: itemId}), { + height: "23em", + callback: function () { + teaweb.success("保存成功", function () { + teaweb.reload() + }) + } + }) + } +}) \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/waf/@menu.html b/web/views/@default/servers/server/settings/waf/@menu.html index f6608570..503f1178 100644 --- a/web/views/@default/servers/server/settings/waf/@menu.html +++ b/web/views/@default/servers/server/settings/waf/@menu.html @@ -2,8 +2,10 @@ 设置 入站规则 出站规则 + | 国家/地区封禁 省份封禁 白名单 黑名单 + IP检查 \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/waf/ipadmin/index.css b/web/views/@default/servers/server/settings/waf/ipadmin/index.css deleted file mode 100644 index e9c43720..00000000 --- a/web/views/@default/servers/server/settings/waf/ipadmin/index.css +++ /dev/null @@ -1,16 +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; -} -/*# sourceMappingURL=index.css.map */ \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/waf/ipadmin/index.css.map b/web/views/@default/servers/server/settings/waf/ipadmin/index.css.map deleted file mode 100644 index be1a9f01..00000000 --- a/web/views/@default/servers/server/settings/waf/ipadmin/index.css.map +++ /dev/null @@ -1 +0,0 @@ -{"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"} \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/waf/ipadmin/index.html b/web/views/@default/servers/server/settings/waf/ipadmin/index.html deleted file mode 100644 index 232040fd..00000000 --- a/web/views/@default/servers/server/settings/waf/ipadmin/index.html +++ /dev/null @@ -1,51 +0,0 @@ -{$layout} - - {$template "../waf_menu"} - {$template "menu"} - -
- - - - - - - - - - -
已封禁 - 暂时没有选择封禁区域。 -
- - ({{country.letter}}){{country.name}} -
-
选择封禁区域 - 选择区域 - - -
-
-

{{letter}}

-
-
-
- - -
-
-
-
-
-
-
- -
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/waf/ipadmin/index.js b/web/views/@default/servers/server/settings/waf/ipadmin/index.js deleted file mode 100644 index 450fcf99..00000000 --- a/web/views/@default/servers/server/settings/waf/ipadmin/index.js +++ /dev/null @@ -1,66 +0,0 @@ -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 - } - }) - } -}) \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/waf/ipadmin/index.less b/web/views/@default/servers/server/settings/waf/ipadmin/index.less deleted file mode 100644 index f6774ab9..00000000 --- a/web/views/@default/servers/server/settings/waf/ipadmin/index.less +++ /dev/null @@ -1,22 +0,0 @@ -.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/server/settings/waf/ipadmin/test.html b/web/views/@default/servers/server/settings/waf/ipadmin/test.html new file mode 100644 index 00000000..b0e426aa --- /dev/null +++ b/web/views/@default/servers/server/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/server/settings/waf/ipadmin/test.js b/web/views/@default/servers/server/settings/waf/ipadmin/test.js new file mode 100644 index 00000000..a5ebe857 --- /dev/null +++ b/web/views/@default/servers/server/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: "24em", + callback: function () { + teaweb.success("保存成功", function () { + + }) + } + }) + } +}) \ No newline at end of file