mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-06 23:00:25 +08:00
IPBox增加地域、ISP、添加到黑名单等功能
This commit is contained in:
40
internal/web/actions/default/servers/ipbox/addIP.go
Normal file
40
internal/web/actions/default/servers/ipbox/addIP.go
Normal file
@@ -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()
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ package ipbox
|
|||||||
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/iwind/TeaGo/maps"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -22,10 +23,62 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
}) {
|
}) {
|
||||||
this.Data["ip"] = params.Ip
|
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{
|
accessLogsResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
|
||||||
Day: timeutil.Format("Ymd"),
|
Day: timeutil.Format("Ymd"),
|
||||||
Keyword: "ip:" + params.Ip,
|
Ip: params.Ip,
|
||||||
Size: 10,
|
Size: 20,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -35,9 +88,9 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
if len(accessLogs) == 0 {
|
if len(accessLogs) == 0 {
|
||||||
// 查询昨天
|
// 查询昨天
|
||||||
accessLogsResp, err = this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
|
accessLogsResp, err = this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
|
||||||
Day: timeutil.Format("Ymd", time.Now().AddDate(0, 0, -1)),
|
Day: timeutil.Format("Ymd", time.Now().AddDate(0, 0, -1)),
|
||||||
Keyword: "ip:" + params.Ip,
|
Ip: params.Ip,
|
||||||
Size: 10,
|
Size: 20,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ func init() {
|
|||||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
|
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
|
||||||
Prefix("/servers/ipbox").
|
Prefix("/servers/ipbox").
|
||||||
Get("", new(IndexAction)).
|
Get("", new(IndexAction)).
|
||||||
|
Post("/addIP", new(AddIPAction)).
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ Vue.component("copy-to-clipboard", {
|
|||||||
methods: {
|
methods: {
|
||||||
copy: function () {
|
copy: function () {
|
||||||
new ClipboardJS('[data-clipboard-target]');
|
new ClipboardJS('[data-clipboard-target]');
|
||||||
teaweb.success("已复制到剪切板")
|
teaweb.successToast("已复制到剪切板")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
template: `<a href="" title="拷贝到剪切板" :data-clipboard-target="'#' + vTarget" @click.prevent="copy"><i class="ui icon copy small"></i></em></a>`
|
template: `<a href="" title="拷贝到剪切板" :data-clipboard-target="'#' + vTarget" @click.prevent="copy"><i class="ui icon copy small"></i></em></a>`
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ Vue.component("http-access-log-box", {
|
|||||||
this.$refs.box.parentNode.style.cssText = ""
|
this.$refs.box.parentNode.style.cssText = ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
template: `<div :style="{'color': (accessLog.status >= 400) ? '#dc143c' : ''}" ref="box">
|
template: `<div style="word-break: break-all" :style="{'color': (accessLog.status >= 400) ? '#dc143c' : ''}" ref="box">
|
||||||
<a v-if="accessLog.node != null && accessLog.node.nodeCluster != null" :href="'/clusters/cluster/node?nodeId=' + accessLog.node.id + '&clusterId=' + accessLog.node.nodeCluster.id" title="点击查看节点详情" target="_top"><span class="grey">[{{accessLog.node.name}}<span v-if="!accessLog.node.name.endsWith('节点')">节点</span>]</span></a><span v-if="accessLog.region != null && accessLog.region.length > 0" class="grey">[{{accessLog.region}}]</span> <ip-box><keyword :v-word="vKeyword">{{accessLog.remoteAddr}}</keyword></ip-box> [{{accessLog.timeLocal}}] <em>"<keyword :v-word="vKeyword">{{accessLog.requestMethod}}</keyword> {{accessLog.scheme}}://<keyword :v-word="vKeyword">{{accessLog.host}}</keyword><keyword :v-word="vKeyword">{{accessLog.requestURI}}</keyword> <a :href="accessLog.scheme + '://' + accessLog.host + accessLog.requestURI" target="_blank" title="新窗口打开" class="disabled"><i class="external icon tiny"></i> </a> {{accessLog.proto}}" </em> <keyword :v-word="vKeyword">{{accessLog.status}}</keyword> <code-label v-if="accessLog.attrs != null && accessLog.attrs['cache.status'] == 'HIT'">cache hit</code-label> <code-label v-if="accessLog.firewallActions != null && accessLog.firewallActions.length > 0">waf {{accessLog.firewallActions}}</code-label> <span v-if="accessLog.tags != null && accessLog.tags.length > 0">- <code-label v-for="tag in accessLog.tags">{{tag}}</code-label></span> - 耗时:{{formatCost(accessLog.requestTime)}} ms <span v-if="accessLog.humanTime != null && accessLog.humanTime.length > 0" class="grey small"> ({{accessLog.humanTime}})</span>
|
<a v-if="accessLog.node != null && accessLog.node.nodeCluster != null" :href="'/clusters/cluster/node?nodeId=' + accessLog.node.id + '&clusterId=' + accessLog.node.nodeCluster.id" title="点击查看节点详情" target="_top"><span class="grey">[{{accessLog.node.name}}<span v-if="!accessLog.node.name.endsWith('节点')">节点</span>]</span></a><span v-if="accessLog.region != null && accessLog.region.length > 0" class="grey">[{{accessLog.region}}]</span> <ip-box><keyword :v-word="vKeyword">{{accessLog.remoteAddr}}</keyword></ip-box> [{{accessLog.timeLocal}}] <em>"<keyword :v-word="vKeyword">{{accessLog.requestMethod}}</keyword> {{accessLog.scheme}}://<keyword :v-word="vKeyword">{{accessLog.host}}</keyword><keyword :v-word="vKeyword">{{accessLog.requestURI}}</keyword> <a :href="accessLog.scheme + '://' + accessLog.host + accessLog.requestURI" target="_blank" title="新窗口打开" class="disabled"><i class="external icon tiny"></i> </a> {{accessLog.proto}}" </em> <keyword :v-word="vKeyword">{{accessLog.status}}</keyword> <code-label v-if="accessLog.attrs != null && accessLog.attrs['cache.status'] == 'HIT'">cache hit</code-label> <code-label v-if="accessLog.firewallActions != null && accessLog.firewallActions.length > 0">waf {{accessLog.firewallActions}}</code-label> <span v-if="accessLog.tags != null && accessLog.tags.length > 0">- <code-label v-for="tag in accessLog.tags">{{tag}}</code-label></span> - 耗时:{{formatCost(accessLog.requestTime)}} ms <span v-if="accessLog.humanTime != null && accessLog.humanTime.length > 0" class="grey small"> ({{accessLog.humanTime}})</span>
|
||||||
<a href="" @click.prevent="showLog" title="查看详情"><i class="icon expand"></i></a>
|
<a href="" @click.prevent="showLog" title="查看详情"><i class="icon expand"></i></a>
|
||||||
</div>`
|
</div>`
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<td style="text-align: center;"><i class="icon bars handle grey"></i> </td>
|
<td style="text-align: center;"><i class="icon bars handle grey"></i> </td>
|
||||||
<td>{{group.name}}</td>
|
<td>{{group.name}}</td>
|
||||||
<td class="center">
|
<td class="center">
|
||||||
<span v-if="group.countServers > 0">{{group.countServers}}</span>
|
<a :href="'/servers?groupId=' + group.id" v-if="group.countServers > 0">{{group.countServers}}</a>
|
||||||
<span v-else class="disabled">0</span>
|
<span v-else class="disabled">0</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
9
web/views/@default/servers/ipbox/index.css
Normal file
9
web/views/@default/servers/ipbox/index.css
Normal file
@@ -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 */
|
||||||
1
web/views/@default/servers/ipbox/index.css.map
Normal file
1
web/views/@default/servers/ipbox/index.css.map
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":["index.less"],"names":[],"mappings":"AAAA;EACC,+BAAA;EACA,iBAAA;EACA,UAAA;;AAGD;EACC,UAAA","file":"index.css"}
|
||||||
@@ -1,6 +1,44 @@
|
|||||||
{$layout "layout_popup"}
|
{$layout "layout_popup"}
|
||||||
|
|
||||||
<h3>最近访问日志<span class="grey">({{ip}})</span></h3>
|
<h3>IP最近访问日志<span class="grey">(<span>{{ip}}</span>)</span></h3>
|
||||||
|
|
||||||
|
<table class="ui table definition celled selectable">
|
||||||
|
<tr>
|
||||||
|
<td class="cell-title">IP</td>
|
||||||
|
<td class="cell-content">
|
||||||
|
<span id="ip-text">{{ip}}</span>
|
||||||
|
<copy-to-clipboard :v-target="'ip-text'"></copy-to-clipboard>
|
||||||
|
</td>
|
||||||
|
<td class="cell-title">区域</td>
|
||||||
|
<td class="cell-content">
|
||||||
|
<span v-if="regions.length > 0">{{regions}}</span>
|
||||||
|
<span v-else class="disabled">-</span>
|
||||||
|
</td>
|
||||||
|
<td class="cell-title">ISP</td>
|
||||||
|
<td>
|
||||||
|
<span v-if="isp.length > 0">{{isp}}</span>
|
||||||
|
<span v-else class="disabled">-</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr v-if="publicBlackIPLists.length > 0">
|
||||||
|
<td>所在IP名单</td>
|
||||||
|
<td colspan="5">
|
||||||
|
<div class="ui label basic small" v-for="ipList in ipLists">
|
||||||
|
{{ipList.name}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<a href="" @click.prevent="showBlackLists"><i class="icon angle" :class="{up: blackListsVisible, down: !blackListsVisible}"></i>添加黑名单</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr v-if="publicBlackIPLists.length > 0 && blackListsVisible">
|
||||||
|
<td>加入黑名单</td>
|
||||||
|
<td colspan="5">
|
||||||
|
<a class="ui label basic small" v-for="ipList in publicBlackIPLists" @click.prevent="addBlackIP(ipList)">
|
||||||
|
{{ipList.name}}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
<p class="comment" v-if="accessLogs.length == 0">暂时还没有访问日志。</p>
|
<p class="comment" v-if="accessLogs.length == 0">暂时还没有访问日志。</p>
|
||||||
<table class="ui table selectable" v-if="accessLogs.length > 0">
|
<table class="ui table selectable" v-if="accessLogs.length > 0">
|
||||||
|
|||||||
30
web/views/@default/servers/ipbox/index.js
Normal file
30
web/views/@default/servers/ipbox/index.js
Normal file
@@ -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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
9
web/views/@default/servers/ipbox/index.less
Normal file
9
web/views/@default/servers/ipbox/index.less
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
.cell-title {
|
||||||
|
background: rgba(0, 0, 0, 0.03);
|
||||||
|
font-weight: bold;
|
||||||
|
width: 7em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cell-content {
|
||||||
|
width: 22%;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user