diff --git a/internal/web/actions/default/servers/ipbox/addIP.go b/internal/web/actions/default/servers/ipbox/addIP.go new file mode 100644 index 00000000..3db3089c --- /dev/null +++ b/internal/web/actions/default/servers/ipbox/addIP.go @@ -0,0 +1,40 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package ipbox + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "strings" + "time" +) + +type AddIPAction struct { + actionutils.ParentAction +} + +func (this *AddIPAction) RunPost(params struct { + ListId int64 + Ip string +}) { + var ipType = "ipv4" + if strings.Contains(params.Ip, ":") { + ipType = "ipv6" + } + + _, err := this.RPC().IPItemRPC().CreateIPItem(this.AdminContext(), &pb.CreateIPItemRequest{ + IpListId: params.ListId, + IpFrom: params.Ip, + IpTo: "", + ExpiredAt: time.Now().Unix() + 86400, // TODO 可以自定义时间 + Reason: "从IPBox中加入名单", + Type: ipType, + EventLevel: "critical", + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/ipbox/index.go b/internal/web/actions/default/servers/ipbox/index.go index 2a8fabf3..eeb02523 100644 --- a/internal/web/actions/default/servers/ipbox/index.go +++ b/internal/web/actions/default/servers/ipbox/index.go @@ -5,6 +5,7 @@ package ipbox import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/maps" timeutil "github.com/iwind/TeaGo/utils/time" "time" ) @@ -22,10 +23,62 @@ func (this *IndexAction) RunGet(params struct { }) { this.Data["ip"] = params.Ip + // IP信息 + regionResp, err := this.RPC().IPLibraryRPC().LookupIPRegion(this.AdminContext(), &pb.LookupIPRegionRequest{Ip: params.Ip}) + if err != nil { + this.ErrorPage(err) + return + } + if regionResp.IpRegion != nil { + this.Data["regions"] = regionResp.IpRegion.Summary + } else { + this.Data["regions"] = "" + } + this.Data["isp"] = regionResp.IpRegion.Isp + + // IP列表 + ipListResp, err := this.RPC().IPListRPC().FindEnabledIPListContainsIP(this.AdminContext(), &pb.FindEnabledIPListContainsIPRequest{Ip: params.Ip}) + if err != nil { + this.ErrorPage(err) + return + } + var ipListMaps = []maps.Map{} + for _, ipList := range ipListResp.IpLists { + ipListMaps = append(ipListMaps, maps.Map{ + "id": ipList.Id, + "name": ipList.Name, + "type": ipList.Type, + }) + } + this.Data["ipLists"] = ipListMaps + + // 所有公用的IP列表 + publicBlackIPListResp, err := this.RPC().IPListRPC().ListEnabledIPLists(this.AdminContext(), &pb.ListEnabledIPListsRequest{ + Type: "black", + IsPublic: true, + Keyword: "", + Offset: 0, + Size: 10, // TODO 将来考虑到支持更多的黑名单 + }) + if err != nil { + this.ErrorPage(err) + return + } + var publicBlackIPListMaps = []maps.Map{} + for _, ipList := range publicBlackIPListResp.IpLists { + publicBlackIPListMaps = append(publicBlackIPListMaps, maps.Map{ + "id": ipList.Id, + "name": ipList.Name, + "type": ipList.Type, + }) + } + this.Data["publicBlackIPLists"] = publicBlackIPListMaps + + // 访问日志 accessLogsResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{ - Day: timeutil.Format("Ymd"), - Keyword: "ip:" + params.Ip, - Size: 10, + Day: timeutil.Format("Ymd"), + Ip: params.Ip, + Size: 20, }) if err != nil { this.ErrorPage(err) @@ -35,9 +88,9 @@ func (this *IndexAction) RunGet(params struct { if len(accessLogs) == 0 { // 查询昨天 accessLogsResp, err = this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{ - Day: timeutil.Format("Ymd", time.Now().AddDate(0, 0, -1)), - Keyword: "ip:" + params.Ip, - Size: 10, + Day: timeutil.Format("Ymd", time.Now().AddDate(0, 0, -1)), + Ip: params.Ip, + Size: 20, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/ipbox/init.go b/internal/web/actions/default/servers/ipbox/init.go index 54844485..7c88a2b3 100644 --- a/internal/web/actions/default/servers/ipbox/init.go +++ b/internal/web/actions/default/servers/ipbox/init.go @@ -14,6 +14,7 @@ func init() { Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). Prefix("/servers/ipbox"). Get("", new(IndexAction)). + Post("/addIP", new(AddIPAction)). EndAll() }) -} \ No newline at end of file +} diff --git a/web/public/js/components/common/copy-to-clipboard.js b/web/public/js/components/common/copy-to-clipboard.js index 5793a4f2..c5f85335 100644 --- a/web/public/js/components/common/copy-to-clipboard.js +++ b/web/public/js/components/common/copy-to-clipboard.js @@ -10,7 +10,7 @@ Vue.component("copy-to-clipboard", { methods: { copy: function () { new ClipboardJS('[data-clipboard-target]'); - teaweb.success("已复制到剪切板") + teaweb.successToast("已复制到剪切板") } }, template: `` diff --git a/web/public/js/components/server/http-access-log-box.js b/web/public/js/components/server/http-access-log-box.js index 77542441..76ff2edf 100644 --- a/web/public/js/components/server/http-access-log-box.js +++ b/web/public/js/components/server/http-access-log-box.js @@ -48,7 +48,7 @@ Vue.component("http-access-log-box", { this.$refs.box.parentNode.style.cssText = "" } }, - template: `
+ template: `
[{{accessLog.node.name}}节点][{{accessLog.region}}] {{accessLog.remoteAddr}} [{{accessLog.timeLocal}}] "{{accessLog.requestMethod}} {{accessLog.scheme}}://{{accessLog.host}}{{accessLog.requestURI}} {{accessLog.proto}}" {{accessLog.status}} cache hit waf {{accessLog.firewallActions}} - {{tag}} - 耗时:{{formatCost(accessLog.requestTime)}} ms   ({{accessLog.humanTime}})  
` diff --git a/web/views/@default/servers/components/groups/index.html b/web/views/@default/servers/components/groups/index.html index b4477864..d2633984 100644 --- a/web/views/@default/servers/components/groups/index.html +++ b/web/views/@default/servers/components/groups/index.html @@ -23,7 +23,7 @@ {{group.name}} - {{group.countServers}} + {{group.countServers}} 0 diff --git a/web/views/@default/servers/ipbox/index.css b/web/views/@default/servers/ipbox/index.css new file mode 100644 index 00000000..4685f12e --- /dev/null +++ b/web/views/@default/servers/ipbox/index.css @@ -0,0 +1,9 @@ +.cell-title { + background: rgba(0, 0, 0, 0.03); + font-weight: bold; + width: 7em; +} +.cell-content { + width: 22%; +} +/*# sourceMappingURL=index.css.map */ \ No newline at end of file diff --git a/web/views/@default/servers/ipbox/index.css.map b/web/views/@default/servers/ipbox/index.css.map new file mode 100644 index 00000000..e3c40cd5 --- /dev/null +++ b/web/views/@default/servers/ipbox/index.css.map @@ -0,0 +1 @@ +{"version":3,"sources":["index.less"],"names":[],"mappings":"AAAA;EACC,+BAAA;EACA,iBAAA;EACA,UAAA;;AAGD;EACC,UAAA","file":"index.css"} \ No newline at end of file diff --git a/web/views/@default/servers/ipbox/index.html b/web/views/@default/servers/ipbox/index.html index 8e436681..009a27c1 100644 --- a/web/views/@default/servers/ipbox/index.html +++ b/web/views/@default/servers/ipbox/index.html @@ -1,6 +1,44 @@ {$layout "layout_popup"} -

最近访问日志({{ip}})

+

IP最近访问日志{{ip}}

+ + + + + + + + + + + + + + + + + + +
IP + {{ip}} + + 区域 + {{regions}} + - + ISP + {{isp}} + - +
所在IP名单 +
+ {{ipList.name}} +
+     + 添加黑名单 +
加入黑名单 + + {{ipList.name}} + +

暂时还没有访问日志。

diff --git a/web/views/@default/servers/ipbox/index.js b/web/views/@default/servers/ipbox/index.js new file mode 100644 index 00000000..1ed34fb9 --- /dev/null +++ b/web/views/@default/servers/ipbox/index.js @@ -0,0 +1,30 @@ +Tea.context(function () { + this.blackListsVisible = false + this.allPublicBlackIPLists = this.publicBlackIPLists.$copy() + + this.showBlackLists = function () { + let that = this + this.publicBlackIPLists = this.allPublicBlackIPLists.filter(function (allList) { + let found = true + that.ipLists.forEach(function (list) { + if (allList.id == list.id) { + found = false + } + }) + return found + }) + this.blackListsVisible = !this.blackListsVisible + } + + this.addBlackIP = function (list) { + this.$post(".addIP") + .params({ + listId: list.id, + ip: this.ip + }) + .success(function () { + this.ipLists.push(list) + this.blackListsVisible = false + }) + } +}) \ No newline at end of file diff --git a/web/views/@default/servers/ipbox/index.less b/web/views/@default/servers/ipbox/index.less new file mode 100644 index 00000000..cb173322 --- /dev/null +++ b/web/views/@default/servers/ipbox/index.less @@ -0,0 +1,9 @@ +.cell-title { + background: rgba(0, 0, 0, 0.03); + font-weight: bold; + width: 7em; +} + +.cell-content { + width: 22%; +} \ No newline at end of file