增加全局查看、检索IP功能

This commit is contained in:
GoEdgeLab
2021-11-17 19:50:52 +08:00
parent 65c43e72e0
commit 347d36b8bd
10 changed files with 303 additions and 106 deletions

View File

@@ -5,8 +5,9 @@ package iplists
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ipconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type IndexAction struct {
@@ -18,60 +19,116 @@ func (this *IndexAction) Init() {
}
func (this *IndexAction) RunGet(params struct {
Type string
Keyword string
Ip string
}) {
if len(params.Type) == 0 {
params.Type = ipconfigs.IPListTypeBlack
}
this.Data["type"] = params.Type
this.Data["keyword"] = params.Keyword
this.Data["type"] = ""
this.Data["ip"] = params.Ip
countResp, err := this.RPC().IPListRPC().CountAllEnabledIPLists(this.AdminContext(), &pb.CountAllEnabledIPListsRequest{
Type: params.Type,
IsPublic: true,
Keyword: params.Keyword,
})
countResp, err := this.RPC().IPItemRPC().CountAllEnabledIPItems(this.AdminContext(), &pb.CountAllEnabledIPItemsRequest{Ip: params.Ip})
if err != nil {
this.ErrorPage(err)
return
}
count := countResp.Count
page := this.NewPage(count)
var count = countResp.Count
var page = this.NewPage(count)
this.Data["page"] = page.AsHTML()
listsResp, err := this.RPC().IPListRPC().ListEnabledIPLists(this.AdminContext(), &pb.ListEnabledIPListsRequest{
Type: params.Type,
IsPublic: true,
Keyword: params.Keyword,
Offset: page.Offset,
Size: page.Size,
itemsResp, err := this.RPC().IPItemRPC().ListAllEnabledIPItems(this.AdminContext(), &pb.ListAllEnabledIPItemsRequest{
Ip: params.Ip,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var listMaps = []maps.Map{}
for _, list := range listsResp.IpLists {
// 包含的IP数量
countItemsResp, err := this.RPC().IPItemRPC().CountIPItemsWithListId(this.AdminContext(), &pb.CountIPItemsWithListIdRequest{IpListId: list.Id})
if err != nil {
this.ErrorPage(err)
return
}
var countItems = countItemsResp.Count
listMaps = append(listMaps, maps.Map{
"id": list.Id,
"isOn": list.IsOn,
"name": list.Name,
"description": list.Description,
"countItems": countItems,
"type": list.Type,
"isGlobal": list.IsGlobal,
var itemMaps = []maps.Map{}
for _, result := range itemsResp.Results {
var item = result.IpItem
expiredTime := ""
if item.ExpiredAt > 0 {
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
}
// policy
var sourcePolicyMap = maps.Map{"id": 0}
if item.SourceHTTPFirewallPolicy != nil {
sourcePolicyMap = maps.Map{
"id": item.SourceHTTPFirewallPolicy.Id,
"name": item.SourceHTTPFirewallPolicy.Name,
"serverId": item.SourceHTTPFirewallPolicy.ServerId,
}
}
// group
var sourceGroupMap = maps.Map{"id": 0}
if item.SourceHTTPFirewallRuleGroup != nil {
sourceGroupMap = maps.Map{
"id": item.SourceHTTPFirewallRuleGroup.Id,
"name": item.SourceHTTPFirewallRuleGroup.Name,
}
}
// set
var sourceSetMap = maps.Map{"id": 0}
if item.SourceHTTPFirewallRuleSet != nil {
sourceSetMap = maps.Map{
"id": item.SourceHTTPFirewallRuleSet.Id,
"name": item.SourceHTTPFirewallRuleSet.Name,
}
}
// server
var sourceServerMap = maps.Map{"id": 0}
if item.SourceServer != nil {
sourceServerMap = maps.Map{
"id": item.SourceServer.Id,
"name": item.SourceServer.Name,
}
}
// IP名单
var listMap = maps.Map{"id": 0}
if result.IpList != nil {
listMap = maps.Map{
"id": result.IpList.Id,
"name": result.IpList.Name,
"type": result.IpList.Type,
}
}
// policy
var policyMap = maps.Map{"id": 0}
if result.HttpFirewallPolicy != nil {
policyMap = maps.Map{
"id": result.HttpFirewallPolicy.Id,
"name": result.HttpFirewallPolicy.Name,
}
if result.Server != nil {
policyMap["server"] = maps.Map{"id": result.Server.Id, "name": result.Server.Name}
}
}
itemMaps = append(itemMaps, maps.Map{
"id": item.Id,
"ipFrom": item.IpFrom,
"ipTo": item.IpTo,
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
"expiredTime": expiredTime,
"reason": item.Reason,
"type": item.Type,
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
"sourcePolicy": sourcePolicyMap,
"sourceGroup": sourceGroupMap,
"sourceSet": sourceSetMap,
"sourceServer": sourceServerMap,
"list": listMap,
"policy": policyMap,
})
}
this.Data["lists"] = listMaps
this.Data["items"] = itemMaps
this.Show()
}

View File

@@ -14,6 +14,7 @@ func init() {
Data("teaSubMenu", "iplist").
Prefix("/servers/iplists").
Get("", new(IndexAction)).
Get("/lists", new(ListsAction)).
GetPost("/createPopup", new(CreatePopupAction)).
Get("/list", new(ListAction)).
GetPost("/import", new(ImportAction)).
@@ -38,7 +39,6 @@ func init() {
// 选项数据
Post("/levelOptions", new(LevelOptionsAction)).
EndAll()
})
}

View File

@@ -0,0 +1,77 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package iplists
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ipconfigs"
"github.com/iwind/TeaGo/maps"
)
type ListsAction struct {
actionutils.ParentAction
}
func (this *ListsAction) Init() {
this.Nav("", "", "lists")
}
func (this *ListsAction) RunGet(params struct {
Type string
Keyword string
}) {
if len(params.Type) == 0 {
params.Type = ipconfigs.IPListTypeBlack
}
this.Data["type"] = params.Type
this.Data["keyword"] = params.Keyword
countResp, err := this.RPC().IPListRPC().CountAllEnabledIPLists(this.AdminContext(), &pb.CountAllEnabledIPListsRequest{
Type: params.Type,
IsPublic: true,
Keyword: params.Keyword,
})
if err != nil {
this.ErrorPage(err)
return
}
count := countResp.Count
page := this.NewPage(count)
this.Data["page"] = page.AsHTML()
listsResp, err := this.RPC().IPListRPC().ListEnabledIPLists(this.AdminContext(), &pb.ListEnabledIPListsRequest{
Type: params.Type,
IsPublic: true,
Keyword: params.Keyword,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var listMaps = []maps.Map{}
for _, list := range listsResp.IpLists {
// 包含的IP数量
countItemsResp, err := this.RPC().IPItemRPC().CountIPItemsWithListId(this.AdminContext(), &pb.CountIPItemsWithListIdRequest{IpListId: list.Id})
if err != nil {
this.ErrorPage(err)
return
}
var countItems = countItemsResp.Count
listMaps = append(listMaps, maps.Map{
"id": list.Id,
"isOn": list.IsOn,
"name": list.Name,
"description": list.Description,
"countItems": countItems,
"type": list.Type,
"isGlobal": list.IsGlobal,
})
}
this.Data["lists"] = listMaps
this.Show()
}

View File

@@ -38,7 +38,24 @@ Vue.component("ip-list-table", {
<span v-if="item.type != 'all'"><keyword :v-word="keyword">{{item.ipFrom}}</keyword><span v-if="item.ipTo.length > 0"> - <keyword :v-word="keyword">{{item.ipTo}}</keyword></span></span>
<span v-else class="disabled">*</span>
<div v-if="item.createdTime != null">
<span class="small disabled">添加于 {{item.createdTime}}</span>
<span class="small grey">添加于 {{item.createdTime}}
<span v-if="item.list != null && item.list.id > 0">
@
<a :href="'/servers/iplists/list?listId=' + item.list.id" v-if="item.policy.id == 0"><span>[<span v-if="item.list.type == 'black'">黑</span><span v-if="item.list.type == 'white'">白</span>名单:{{item.list.name}}]</span></a>
<span v-else>[<span v-if="item.list.type == 'black'">黑</span><span v-if="item.list.type == 'white'">白</span>名单:{{item.list.name}}</span>
<span v-if="item.policy.id > 0">
<span v-if="item.policy.server != null">
<a :href="'/servers/server/settings/waf/ipadmin/allowList?serverId=' + item.policy.server.id + '&firewallPolicyId=' + item.policy.id" v-if="item.list.type == 'white'">[服务:{{item.policy.server.name}}]</a>
<a :href="'/servers/server/settings/waf/ipadmin/denyList?serverId=' + item.policy.server.id + '&firewallPolicyId=' + item.policy.id" v-if="item.list.type == 'black'">[服务:{{item.policy.server.name}}]</a>
</span>
<span v-else>
<a :href="'/servers/components/waf/ipadmin/lists?firewallPolicyId=' + item.policy.id + '&type=' + item.list.type">[策略:{{item.policy.name}}]</a>
</span>
</span>
</span>
</span>
</div>
</td>
<td>
@@ -65,11 +82,11 @@ Vue.component("ip-list-table", {
<span v-else class="disabled">-</span>
<div style="margin-top: 0.4em" v-if="item.sourceServer != null && item.sourceServer.id > 0">
<a :href="'/servers/server?serverId=' + item.sourceServer.id" class="ui label tiny basic grey" target="_blank"><i class="icon clone outline"></i>{{item.sourceServer.name}}</a>
<a :href="'/servers/server?serverId=' + item.sourceServer.id" style="border: 0"><span class="small "><i class="icon clone outline"></i>{{item.sourceServer.name}}</span></a>
</div>
<div v-if="item.sourcePolicy != null && item.sourcePolicy.id > 0" style="margin-top: 0.4em">
<a :href="'/servers/components/waf/group?firewallPolicyId=' + item.sourcePolicy.id + '&type=inbound&groupId=' + item.sourceGroup.id" v-if="item.sourcePolicy.serverId == 0" class="ui label tiny basic grey" target="_blank"><i class="icon shield"></i>{{item.sourcePolicy.name}} &raquo; {{item.sourceGroup.name}} &raquo; {{item.sourceSet.name}}</a>
<a :href="'/servers/server/settings/waf/group?serverId=' + item.sourcePolicy.serverId + '&firewallPolicyId=' + item.sourcePolicy.id + '&type=inbound&groupId=' + item.sourceGroup.id" v-if="item.sourcePolicy.serverId > 0" class="ui label tiny basic grey" target="_blank"><i class="icon shield"></i> {{item.sourcePolicy.name}} &raquo; {{item.sourceGroup.name}} &raquo; {{item.sourceSet.name}}</a>
<a :href="'/servers/components/waf/group?firewallPolicyId=' + item.sourcePolicy.id + '&type=inbound&groupId=' + item.sourceGroup.id" v-if="item.sourcePolicy.serverId == 0"><span class="small "><i class="icon shield"></i>{{item.sourcePolicy.name}} &raquo; {{item.sourceGroup.name}} &raquo; {{item.sourceSet.name}}</span></a>
<a :href="'/servers/server/settings/waf/group?serverId=' + item.sourcePolicy.serverId + '&firewallPolicyId=' + item.sourcePolicy.id + '&type=inbound&groupId=' + item.sourceGroup.id" v-if="item.sourcePolicy.serverId > 0"><span class="small "><i class="icon shield"></i> {{item.sourcePolicy.name}} &raquo; {{item.sourceGroup.name}} &raquo; {{item.sourceSet.name}}</span></a>
</div>
</td>
<td>

View File

@@ -1,5 +1,5 @@
<first-menu>
<menu-item :href="'/servers/iplists?type=' + list.type">{{list.typeName}}</menu-item>
<menu-item :href="'/servers/iplists/lists?type=' + list.type">{{list.typeName}}</menu-item>
<span class="disabled item">|</span>
<menu-item :href="'/servers/iplists/list?listId=' + list.id" code="list">"{{list.name}}"详情</menu-item>
<menu-item :href="'/servers/iplists/items?listId=' + list.id" code="item">IP({{list.countItems}})</menu-item>

View File

@@ -1,8 +1,9 @@
<first-menu>
<menu-item href="/servers/iplists" :active="type == 'black'">黑名单</menu-item>
<menu-item href="/servers/iplists?type=white" :active="type == 'white'">名单</menu-item>
<span class="item disabled">|</span>
<menu-item @click.prevent="createList">[创建]</menu-item>
<span class="item disabled">|</span>
<span class="item"><tip-icon content="可以在WAF策略里直接引用这些公用名单。"></tip-icon></span>
<menu-item href="/servers/iplists" code="index">所有IP</menu-item>
<menu-item href="/servers/iplists/lists?type=black" :active="type == 'black'">公共黑名单</menu-item>
<menu-item href="/servers/iplists/lists?type=white" :active="type == 'white'">公共白名单</menu-item>
<span class="item disabled" v-if="type.length > 0">|</span>
<menu-item @click.prevent="createList" v-if="type.length > 0">[创建]</menu-item>
<span class="item disabled" v-if="type.length > 0">|</span>
<span class="item" v-if="type.length > 0"><tip-icon content="可以在WAF策略里直接引用这些公用名单。"></tip-icon></span>
</first-menu>

View File

@@ -1,56 +1,22 @@
{$layout}
{$template "menu"}
<tip-message-box code="iplist-public-tip">这里是公用的IP名单可以在WAF策略里直接引用。</tip-message-box>
<div class="margin"></div>
<form class="ui form" action="/servers/iplists">
<input type="hidden" name="type" :value="type"/>
<form class="ui form" action="/servers/iplists" method="get">
<div class="ui fields inline">
<div class="ui field">
<input type="text" placeholder="名称..." name="keyword" v-model="keyword"/>
<input type="text" name="ip" placeholder="x.x.x.x" v-model="ip"/>
</div>
<div class="ui field">
<button type="submit" class="ui button">搜索</button>
&nbsp;
<a :href="'/servers/iplists?type=' + type" v-if="keyword.length > 0">[清除条件]</a>
<button class="ui button" type="submit">搜索</button>
</div>
</div>
</form>
<p class="comment" v-if="lists.length == 0">暂时还没有公用IP名单。</p>
<div class="margin"></div>
<table class="ui table selectable celled" v-if="lists.length > 0">
<thead>
<tr>
<th class="one wide center">ID</th>
<th class="three wide">名称</th>
<th class="two wide center">类型</th>
<th>备注</th>
<th class="two wide center">IP数量</th>
<th class="two op">操作</th>
</tr>
</thead>
<tr v-for="list in lists">
<td class="center">{{list.id}}</td>
<td>
<a :href="'/servers/iplists/list?listId=' + list.id"><keyword :v-word="keyword">{{list.name}}</keyword></a>
<div v-if="list.isGlobal" style="margin-top: 0.3em"><grey-label>全局</grey-label></div>
</td>
<td class="center">
<span v-if="list.type == 'black'">黑名单</span>
<span v-if="list.type == 'white'">白名单</span>
</td>
<td>{{list.description}}</td>
<td class="center">
<a :href="'/servers/iplists/items?listId=' + list.id" v-if="list.countItems > 0">{{list.countItems}}</a>
<span v-else class="disabled">0</span>
</td>
<td>
<a :href="'/servers/iplists/list?listId=' + list.id">详情</a> &nbsp;
<a href="" @click.prevent="deleteList(list.id)">删除</a>
</td>
</tr>
</table>
<p class="comment" v-if="items.length == 0">暂时还没有IP。</p>
<ip-list-table v-if="items.length > 0" :v-items="items" @update-item="updateItem" @delete-item="deleteItem" :v-keyword="ip"></ip-list-table>
<div class="page" v-html="page"></div>

View File

@@ -1,27 +1,23 @@
Tea.context(function () {
this.createList = function () {
teaweb.popup(Tea.url(".createPopup", {type: this.type}), {
height: "24em",
callback: function (resp) {
this.updateItem = function (itemId) {
teaweb.popup(Tea.url(".updateIPPopup", {itemId: itemId}), {
height: "26em",
callback: function () {
teaweb.success("保存成功", function () {
window.location = "/servers/iplists?type=" + resp.data.list.type
teaweb.reload()
})
}
})
}
this.deleteList = function (listId) {
this.deleteItem = function (itemId) {
let that = this
teaweb.confirm("确定要删除此IP名单吗?", function () {
that.$post(".delete")
teaweb.confirm("确定要删除这个IP吗?", function () {
that.$post(".deleteIP")
.params({
listId: listId
})
.success(function () {
teaweb.success("删除成功", function () {
teaweb.reload()
})
"itemId": itemId
})
.refresh()
})
}
})

View File

@@ -0,0 +1,56 @@
{$layout}
{$template "menu"}
<tip-message-box code="iplist-public-tip">这里是公用的IP名单可以在WAF策略里直接引用。</tip-message-box>
<div class="margin"></div>
<form class="ui form" action="/servers/iplists">
<input type="hidden" name="type" :value="type"/>
<div class="ui fields inline">
<div class="ui field">
<input type="text" placeholder="名称..." name="keyword" v-model="keyword"/>
</div>
<div class="ui field">
<button type="submit" class="ui button">搜索</button>
&nbsp;
<a :href="'/servers/iplists?type=' + type" v-if="keyword.length > 0">[清除条件]</a>
</div>
</div>
</form>
<p class="comment" v-if="lists.length == 0">暂时还没有公用IP名单。</p>
<table class="ui table selectable celled" v-if="lists.length > 0">
<thead>
<tr>
<th class="one wide center">ID</th>
<th class="three wide">名称</th>
<th class="two wide center">类型</th>
<th>备注</th>
<th class="two wide center">IP数量</th>
<th class="two op">操作</th>
</tr>
</thead>
<tr v-for="list in lists">
<td class="center">{{list.id}}</td>
<td>
<a :href="'/servers/iplists/list?listId=' + list.id"><keyword :v-word="keyword">{{list.name}}</keyword></a>
<div v-if="list.isGlobal" style="margin-top: 0.3em"><grey-label>全局</grey-label></div>
</td>
<td class="center">
<span v-if="list.type == 'black'">黑名单</span>
<span v-if="list.type == 'white'">白名单</span>
</td>
<td>{{list.description}}</td>
<td class="center">
<a :href="'/servers/iplists/items?listId=' + list.id" v-if="list.countItems > 0">{{list.countItems}}</a>
<span v-else class="disabled">0</span>
</td>
<td>
<a :href="'/servers/iplists/list?listId=' + list.id">详情</a> &nbsp;
<a href="" @click.prevent="deleteList(list.id)">删除</a>
</td>
</tr>
</table>
<div class="page" v-html="page"></div>

View File

@@ -0,0 +1,27 @@
Tea.context(function () {
this.createList = function () {
teaweb.popup(Tea.url(".createPopup", {type: this.type}), {
height: "24em",
callback: function (resp) {
teaweb.success("保存成功", function () {
window.location = "/servers/iplists/lists?type=" + resp.data.list.type
})
}
})
}
this.deleteList = function (listId) {
let that = this
teaweb.confirm("确定要删除此IP名单吗", function () {
that.$post(".delete")
.params({
listId: listId
})
.success(function () {
teaweb.success("删除成功", function () {
teaweb.reload()
})
})
})
}
})