2019-08-07 13:16:23 +08:00
|
|
|
package fish
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"net/http"
|
|
|
|
"HFish/core/dbUtil"
|
|
|
|
"HFish/error"
|
2019-08-08 09:52:05 +08:00
|
|
|
"HFish/utils/page"
|
|
|
|
"strconv"
|
2019-08-25 01:00:42 +08:00
|
|
|
"strings"
|
2019-08-07 13:16:23 +08:00
|
|
|
)
|
|
|
|
|
2019-08-11 20:14:28 +08:00
|
|
|
// 蜜罐 页面
|
2019-08-07 13:16:23 +08:00
|
|
|
func Html(c *gin.Context) {
|
|
|
|
c.HTML(http.StatusOK, "fish.html", gin.H{})
|
|
|
|
}
|
|
|
|
|
2019-08-11 20:14:28 +08:00
|
|
|
// 获取蜜罐列表
|
2019-08-07 13:16:23 +08:00
|
|
|
func GetFishList(c *gin.Context) {
|
2019-08-08 09:52:05 +08:00
|
|
|
p, _ := c.GetQuery("page")
|
|
|
|
pageSize, _ := c.GetQuery("pageSize")
|
2019-08-09 10:13:54 +08:00
|
|
|
typex, _ := c.GetQuery("type")
|
2019-08-25 01:00:42 +08:00
|
|
|
colony, _ := c.GetQuery("colony")
|
2019-08-09 10:13:54 +08:00
|
|
|
soText, _ := c.GetQuery("so_text")
|
2019-08-08 09:52:05 +08:00
|
|
|
|
|
|
|
pInt, _ := strconv.ParseInt(p, 10, 64)
|
|
|
|
pageSizeInt, _ := strconv.ParseInt(pageSize, 10, 64)
|
|
|
|
|
|
|
|
pageStart := page.Start(pInt, pageSizeInt)
|
|
|
|
|
2019-08-25 01:00:42 +08:00
|
|
|
sql := `select id,type,project_name,agent,ip,country,region,city,create_time,info from hfish_info where 1=1`
|
2019-08-09 10:13:54 +08:00
|
|
|
sqlx := `select count(1) as sum from hfish_info where 1=1`
|
|
|
|
sqlStatus := 0
|
2019-08-08 09:52:05 +08:00
|
|
|
|
2019-08-09 10:13:54 +08:00
|
|
|
if typex != "all" {
|
|
|
|
sql = sql + ` and type=?`
|
|
|
|
sqlx = sqlx + ` and type=?`
|
|
|
|
sqlStatus = 1
|
|
|
|
}
|
|
|
|
|
2019-08-25 01:00:42 +08:00
|
|
|
if colony != "all" {
|
|
|
|
sql = sql + ` and agent=?`
|
|
|
|
sqlx = sqlx + ` and agent=?`
|
|
|
|
if sqlStatus == 1 {
|
|
|
|
sqlStatus = 3
|
|
|
|
} else {
|
|
|
|
sqlStatus = 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 10:13:54 +08:00
|
|
|
if soText != "" {
|
|
|
|
sql = sql + ` and (project_name like ? or ip like ?)`
|
|
|
|
sqlx = sqlx + ` and type=?`
|
2019-08-25 01:00:42 +08:00
|
|
|
|
2019-08-09 10:13:54 +08:00
|
|
|
if sqlStatus == 1 {
|
2019-08-25 01:00:42 +08:00
|
|
|
sqlStatus = 4
|
|
|
|
} else if sqlStatus == 2 {
|
|
|
|
sqlStatus = 5
|
|
|
|
} else if sqlStatus == 3 {
|
|
|
|
sqlStatus = 6
|
2019-08-09 10:13:54 +08:00
|
|
|
} else {
|
2019-08-25 01:00:42 +08:00
|
|
|
sqlStatus = 7
|
2019-08-09 10:13:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sql = sql + ` ORDER BY id desc LIMIT ?,?;`
|
|
|
|
|
|
|
|
if sqlStatus == 0 {
|
|
|
|
result := dbUtil.Query(sql, pageStart, pageSizeInt)
|
|
|
|
resultx := dbUtil.Query(sqlx)
|
2019-08-25 01:00:42 +08:00
|
|
|
totalCount := resultx[0]["sum"].(int64)
|
|
|
|
pageCount := page.TotalPage(totalCount, pageSizeInt)
|
2019-08-09 10:13:54 +08:00
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
2019-08-25 01:00:42 +08:00
|
|
|
"data": result,
|
|
|
|
"pageCount": pageCount,
|
|
|
|
"totalCount": totalCount,
|
|
|
|
"page": p,
|
2019-08-09 10:13:54 +08:00
|
|
|
})
|
|
|
|
} else if sqlStatus == 1 {
|
|
|
|
result := dbUtil.Query(sql, typex, pageStart, pageSizeInt)
|
|
|
|
resultx := dbUtil.Query(sqlx, typex)
|
2019-08-25 01:00:42 +08:00
|
|
|
totalCount := resultx[0]["sum"].(int64)
|
|
|
|
pageCount := page.TotalPage(totalCount, pageSizeInt)
|
2019-08-09 10:13:54 +08:00
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
2019-08-25 01:00:42 +08:00
|
|
|
"data": result,
|
|
|
|
"pageCount": pageCount,
|
|
|
|
"totalCount": totalCount,
|
|
|
|
"page": p,
|
2019-08-09 10:13:54 +08:00
|
|
|
})
|
|
|
|
} else if sqlStatus == 2 {
|
2019-08-25 01:00:42 +08:00
|
|
|
result := dbUtil.Query(sql, colony, pageStart, pageSizeInt)
|
|
|
|
resultx := dbUtil.Query(sqlx, colony)
|
|
|
|
totalCount := resultx[0]["sum"].(int64)
|
|
|
|
pageCount := page.TotalPage(totalCount, pageSizeInt)
|
2019-08-09 10:13:54 +08:00
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
2019-08-25 01:00:42 +08:00
|
|
|
"data": result,
|
|
|
|
"pageCount": pageCount,
|
|
|
|
"totalCount": totalCount,
|
|
|
|
"page": p,
|
2019-08-09 10:13:54 +08:00
|
|
|
})
|
|
|
|
} else if sqlStatus == 3 {
|
2019-08-25 01:00:42 +08:00
|
|
|
result := dbUtil.Query(sql, typex, colony, pageStart, pageSizeInt)
|
|
|
|
resultx := dbUtil.Query(sqlx, typex, colony)
|
|
|
|
totalCount := resultx[0]["sum"].(int64)
|
|
|
|
pageCount := page.TotalPage(totalCount, pageSizeInt)
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"data": result,
|
|
|
|
"pageCount": pageCount,
|
|
|
|
"totalCount": totalCount,
|
|
|
|
"page": p,
|
|
|
|
})
|
|
|
|
} else if sqlStatus == 4 {
|
2019-08-09 10:13:54 +08:00
|
|
|
result := dbUtil.Query(sql, typex, "%"+soText+"%", "%"+soText+"%", pageStart, pageSizeInt)
|
|
|
|
resultx := dbUtil.Query(sqlx, typex, "%"+soText+"%", "%"+soText+"%")
|
2019-08-25 01:00:42 +08:00
|
|
|
totalCount := resultx[0]["sum"].(int64)
|
|
|
|
pageCount := page.TotalPage(totalCount, pageSizeInt)
|
2019-08-09 10:13:54 +08:00
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
2019-08-25 01:00:42 +08:00
|
|
|
"data": result,
|
|
|
|
"pageCount": pageCount,
|
|
|
|
"totalCount": totalCount,
|
|
|
|
"page": p,
|
|
|
|
})
|
|
|
|
} else if sqlStatus == 5 {
|
|
|
|
result := dbUtil.Query(sql, colony, "%"+soText+"%", "%"+soText+"%", pageStart, pageSizeInt)
|
|
|
|
resultx := dbUtil.Query(sqlx, colony, "%"+soText+"%", "%"+soText+"%")
|
|
|
|
totalCount := resultx[0]["sum"].(int64)
|
|
|
|
pageCount := page.TotalPage(totalCount, pageSizeInt)
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"data": result,
|
|
|
|
"pageCount": pageCount,
|
|
|
|
"totalCount": totalCount,
|
|
|
|
"page": p,
|
|
|
|
})
|
|
|
|
} else if sqlStatus == 6 {
|
|
|
|
result := dbUtil.Query(sql, typex, colony, "%"+soText+"%", "%"+soText+"%", pageStart, pageSizeInt)
|
|
|
|
resultx := dbUtil.Query(sqlx, typex, colony, "%"+soText+"%", "%"+soText+"%")
|
|
|
|
totalCount := resultx[0]["sum"].(int64)
|
|
|
|
pageCount := page.TotalPage(totalCount, pageSizeInt)
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"data": result,
|
|
|
|
"pageCount": pageCount,
|
|
|
|
"totalCount": totalCount,
|
|
|
|
"page": p,
|
|
|
|
})
|
|
|
|
} else if sqlStatus == 7 {
|
|
|
|
result := dbUtil.Query(sql, "%"+soText+"%", "%"+soText+"%", pageStart, pageSizeInt)
|
|
|
|
resultx := dbUtil.Query(sqlx, "%"+soText+"%", "%"+soText+"%")
|
|
|
|
totalCount := resultx[0]["sum"].(int64)
|
|
|
|
pageCount := page.TotalPage(totalCount, pageSizeInt)
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"data": result,
|
|
|
|
"pageCount": pageCount,
|
|
|
|
"totalCount": totalCount,
|
|
|
|
"page": p,
|
2019-08-09 10:13:54 +08:00
|
|
|
})
|
|
|
|
}
|
2019-08-07 13:16:23 +08:00
|
|
|
}
|
|
|
|
|
2019-08-11 20:14:28 +08:00
|
|
|
// 删除蜜罐
|
2019-08-07 13:16:23 +08:00
|
|
|
func PostFishDel(c *gin.Context) {
|
|
|
|
id := c.PostForm("id")
|
2019-08-25 01:00:42 +08:00
|
|
|
|
|
|
|
idx := strings.Split(id, ",")
|
|
|
|
|
|
|
|
// 暂时此种方式,待优化
|
|
|
|
for _, x := range idx {
|
|
|
|
sqlDel := `delete from hfish_info where id in (?);`
|
|
|
|
dbUtil.Delete(sqlDel, x)
|
|
|
|
}
|
|
|
|
|
2019-08-07 13:16:23 +08:00
|
|
|
c.JSON(http.StatusOK, error.ErrSuccessNull())
|
|
|
|
}
|
|
|
|
|
2019-08-11 20:14:28 +08:00
|
|
|
// 获取蜜罐信息
|
2019-08-07 13:16:23 +08:00
|
|
|
func GetFishInfo(c *gin.Context) {
|
|
|
|
id, _ := c.GetQuery("id")
|
|
|
|
sql := `select info from hfish_info where id=?;`
|
|
|
|
result := dbUtil.Query(sql, id)
|
|
|
|
c.JSON(http.StatusOK, error.ErrSuccess(result))
|
|
|
|
}
|
2019-08-09 10:13:54 +08:00
|
|
|
|
2019-08-25 01:00:42 +08:00
|
|
|
// 获取蜜罐分类信息,集群信息
|
2019-08-09 10:13:54 +08:00
|
|
|
func GetFishTypeInfo(c *gin.Context) {
|
2019-08-25 01:00:42 +08:00
|
|
|
sqlInfoType := `select type from hfish_info GROUP BY type;`
|
|
|
|
resultInfoType := dbUtil.Query(sqlInfoType)
|
|
|
|
|
|
|
|
sqlColonyName := `select agent_name from hfish_colony GROUP BY agent_name;`
|
|
|
|
resultColonyName := dbUtil.Query(sqlColonyName)
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"resultInfoType": resultInfoType,
|
|
|
|
"resultColonyName": resultColonyName,
|
|
|
|
})
|
2019-08-09 10:13:54 +08:00
|
|
|
}
|