mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2026-09-01 15:32:55 +08:00
增加前后台互联,有缺陷后续改造
This commit is contained in:
+45
-4
@@ -3,24 +3,65 @@ package main
|
||||
import (
|
||||
"SamWaf/global"
|
||||
"SamWaf/innerbean"
|
||||
"SamWaf/model/common/response"
|
||||
"SamWaf/model/waflog/request"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func Cors() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
method := c.Request.Method
|
||||
origin := c.Request.Header.Get("Origin") //请求头部
|
||||
if origin != "" {
|
||||
//TODO 将来要控制 蔡鹏 20221005
|
||||
// 将该域添加到allow-origin中
|
||||
c.Header("Access-Control-Allow-Origin", origin) //
|
||||
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
|
||||
c.Header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
|
||||
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type")
|
||||
//允许客户端传递校验信息比如 cookie
|
||||
c.Header("Access-Control-Allow-Credentials", "true")
|
||||
}
|
||||
if method == "OPTIONS" {
|
||||
c.AbortWithStatus(http.StatusNoContent)
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
func StartLocalServer() {
|
||||
r := gin.Default()
|
||||
r.Use(Cors()) //解决跨域
|
||||
|
||||
r.GET("/ping", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "pong",
|
||||
})
|
||||
})
|
||||
r.GET("/list_log", func(c *gin.Context) {
|
||||
var weblogs []innerbean.WebLog
|
||||
global.GWAF_LOCAL_DB.Debug().Find(&weblogs)
|
||||
var waf_attack request.WafAttackLogSearch
|
||||
r.GET("/samwaf/waflog/attack/list", func(c *gin.Context) {
|
||||
err := c.ShouldBind(&waf_attack)
|
||||
if err == nil {
|
||||
|
||||
var total int64 = 0
|
||||
var weblogs []innerbean.WebLog
|
||||
global.GWAF_LOCAL_DB.Debug().Limit(waf_attack.PageSize).Offset(waf_attack.PageSize * (waf_attack.PageIndex - 1)).Find(&weblogs)
|
||||
global.GWAF_LOCAL_DB.Debug().Count(&total)
|
||||
|
||||
c.JSON(http.StatusOK, response.Response{
|
||||
Code: 200,
|
||||
Data: response.PageResult{
|
||||
List: weblogs,
|
||||
Total: total,
|
||||
PageIndex: waf_attack.PageIndex,
|
||||
PageSize: waf_attack.PageSize,
|
||||
},
|
||||
Msg: "获取成功",
|
||||
})
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, weblogs)
|
||||
})
|
||||
r.Run(":" + strconv.Itoa(global.GWAF_LOCAL_SERVER_PORT)) // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
|
||||
log.Println("本地 port:%d", global.GWAF_LOCAL_SERVER_PORT)
|
||||
|
||||
+2
-11
@@ -3,22 +3,13 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<script src="https://cdn-go.cn/aegis/aegis-sdk/latest/aegis.min.18.js"></script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
<title>TDesign Starter</title>
|
||||
<title>SAM 网站安全防护后台</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
<script language="javascript">
|
||||
if (window.location.host === 'tdesign.tencent.com') {
|
||||
const aegis = new Aegis({
|
||||
id: 'rDISNMyXgqWDFPyHMB', // 项目ID,即上报key
|
||||
reportAssetSpeed: true, // 静态资源测速
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export default {
|
||||
development: {
|
||||
// 开发环境接口请求
|
||||
API: '',
|
||||
API: 'http://127.0.0.1:26666/samwaf',
|
||||
// 开发环境 cdn 路径
|
||||
CDN: '',
|
||||
},
|
||||
|
||||
@@ -44,3 +44,10 @@ export const NOTIFICATION_TYPES = {
|
||||
middle: 'warning',
|
||||
high: 'danger',
|
||||
};
|
||||
|
||||
// 攻击类型TAG类型
|
||||
export const ATTACK_TYPES = {
|
||||
CC: 0,
|
||||
CMD: 1,
|
||||
WEBUPLOAD: 2,
|
||||
};
|
||||
|
||||
@@ -3,9 +3,10 @@ import VueRouter from 'vue-router';
|
||||
import baseRouters from './modules/base';
|
||||
import componentsRouters from './modules/components';
|
||||
import othersRouters from './modules/others';
|
||||
import waflogRouters from './modules/waflog';
|
||||
|
||||
// 存放动态路由
|
||||
export const asyncRouterList = [...baseRouters, ...componentsRouters, ...othersRouters];
|
||||
export const asyncRouterList = [...baseRouters, ...componentsRouters, ...othersRouters,...waflogRouters];
|
||||
|
||||
// 存放固定的路由
|
||||
const defaultRouterList = [
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package request
|
||||
|
||||
type PageInfo struct {
|
||||
PageIndex int `json:"pageIndex" form:"pageIndex"` //当前页面索引
|
||||
PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
|
||||
Keyword string `json:"keyWord" form:"keyWord"` //关键字
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package response
|
||||
|
||||
type PageResult struct {
|
||||
List interface{} `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
PageIndex int `json:"pageIndex"`
|
||||
PageSize int `json:"pageSize"`
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package response
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Data interface{} `json:"data"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package request
|
||||
|
||||
import "SamWaf/model/common/request"
|
||||
|
||||
type WafAttackLogSearch struct {
|
||||
request.PageInfo
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package waflog
|
||||
|
||||
type WafAttackLog struct {
|
||||
}
|
||||
Reference in New Issue
Block a user