- 增加资产列表使用IP端口查询的功能

This commit is contained in:
dushixiang 2022-11-06 18:04:11 +08:00
parent a52ad2e356
commit fd8b36dcc2
3 changed files with 22 additions and 3 deletions

View File

@ -118,12 +118,13 @@ func (assetApi AssetApi) AssetPagingEndpoint(c echo.Context) error {
protocol := c.QueryParam("protocol")
tags := c.QueryParam("tags")
ip := c.QueryParam("ip")
port := c.QueryParam("port")
active := c.QueryParam("active")
order := c.QueryParam("order")
field := c.QueryParam("field")
items, total, err := repository.AssetRepository.Find(context.Background(), pageIndex, pageSize, name, protocol, tags, ip, active, order, field)
items, total, err := repository.AssetRepository.Find(context.Background(), pageIndex, pageSize, name, protocol, tags, ip, port, active, order, field)
if err != nil {
return err
}

View File

@ -43,7 +43,7 @@ func (r assetRepository) FindByProtocolAndIds(c context.Context, protocol string
return
}
func (r assetRepository) Find(c context.Context, pageIndex, pageSize int, name, protocol, tags, ip, active, order, field string) (o []model.AssetForPage, total int64, err error) {
func (r assetRepository) Find(c context.Context, pageIndex, pageSize int, name, protocol, tags, ip, port, active, order, field string) (o []model.AssetForPage, total int64, err error) {
db := r.GetDB(c).Table("assets").Select("assets.id,assets.name,assets.ip,assets.port,assets.protocol,assets.active,assets.active_message,assets.owner,assets.created,assets.tags,assets.description, users.nickname as owner_name").Joins("left join users on assets.owner = users.id")
dbCounter := r.GetDB(c).Table("assets")
@ -57,6 +57,11 @@ func (r assetRepository) Find(c context.Context, pageIndex, pageSize int, name,
dbCounter = dbCounter.Where("assets.ip like ?", "%"+ip+"%")
}
if len(port) > 0 {
db = db.Where("assets.port = ?", port)
dbCounter = dbCounter.Where("assets.port = ?", ip)
}
if len(protocol) > 0 {
db = db.Where("assets.protocol = ?", protocol)
dbCounter = dbCounter.Where("assets.protocol = ?", protocol)

View File

@ -116,7 +116,9 @@ const Asset = () => {
title: '网络',
dataIndex: 'network',
key: 'network',
hideInSearch: true,
fieldProps: {
placeholder: '示例: 127.0.0.1:22'
},
render: (text, record) => {
return `${record['ip'] + ':' + record['port']}`;
}
@ -346,6 +348,15 @@ const Asset = () => {
order = Object.values(sort)[0];
}
let ip, port;
if (params.network) {
let split = params.network.split(':');
if (split.length >= 2) {
ip = split[0];
port = split[1];
}
}
let queryParams = {
pageIndex: params.current,
pageSize: params.pageSize,
@ -354,6 +365,8 @@ const Asset = () => {
protocol: params.protocol,
active: params.active,
'tags': params.tags?.join(','),
ip: ip,
port: port,
field: field,
order: order
}