mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2026-11-01 02:31:39 +08:00
feat:1.增加优化日志列表;2增加日志快速增加黑名单IP; 3.增加响应编码
This commit is contained in:
@@ -24,6 +24,8 @@ type WebLog struct {
|
||||
Day int `json:"day"` //日 (主要键)
|
||||
ACTION string `json:"action"`
|
||||
RULE string `json:"rule"`
|
||||
STATUS string `json:"status"` //状态
|
||||
STATUS_CODE int `json:"status_code"` //状态编码
|
||||
}
|
||||
type WAFLog struct {
|
||||
REQ_UUID string `json:"req_uuid"`
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
"nprogress": "^0.2.0",
|
||||
"qrcode.vue": "^1.7.0",
|
||||
"tdesign-icons-vue": "^0.1.4",
|
||||
"tdesign-vue": "^1.5.0",
|
||||
"tdesign-vue": "^1.6.3",
|
||||
"tvision-color": "~1.4.0",
|
||||
"typescript": "^4.2.4",
|
||||
"vue": "~2.6.14",
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<template>
|
||||
<div class="detail-base">
|
||||
<t-card title="防御情况" class="container-base-margin-top">
|
||||
<t-steps class="detail-base-info-steps" layout="horizontal" theme="dot" :current="2">
|
||||
<t-steps class="detail-base-info-steps" layout="horizontal" theme="dot" :current="3">
|
||||
<t-step-item title="访问" :content="detail_data.create_time" />
|
||||
<t-step-item title="检测" :content="detail_data.create_time" />
|
||||
<t-step-item title="防御状态" :content="detail_data.action" />
|
||||
<t-step-item title="响应状态" :content="detail_data.status" />
|
||||
</t-steps>
|
||||
</t-card>
|
||||
<t-card title="本次请求详情">
|
||||
@@ -27,12 +28,6 @@
|
||||
{{ detail_data.host }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<h1> 请求路径</h1>
|
||||
<span>
|
||||
{{ detail_data.url }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<h1> 请求方法</h1>
|
||||
<span>
|
||||
@@ -49,6 +44,7 @@
|
||||
<h1> 访问者IP</h1>
|
||||
<span>
|
||||
{{ detail_data.src_ip }}
|
||||
<t-button theme="primary" shape="round" size="small" @click="handleAddipblock">加黑名单</t-button>
|
||||
</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
@@ -63,23 +59,37 @@
|
||||
{{ detail_data.country }} {{ detail_data.province }} {{ detail_data.city }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<h1> 响应编码</h1>
|
||||
<span>
|
||||
{{ detail_data.status_code }} ({{detail_data.status}} )
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</t-card>
|
||||
<t-card title="访问其他记录" class="container-base-margin-top">
|
||||
|
||||
<t-list :split="true">
|
||||
<t-list-item>
|
||||
<t-list-item-meta title="请求头" :description="detail_data.header"></t-list-item-meta>
|
||||
<t-list-item-meta title="请求路径"></t-list-item-meta>
|
||||
</t-list-item>
|
||||
<t-textarea v-model="detail_data.url" :autosize="{ minRows: 3, maxRows: 5 }" readonly/>
|
||||
<t-list-item>
|
||||
<t-list-item-meta title="请求用户浏览器" :description="detail_data.user_agent"></t-list-item-meta>
|
||||
<t-list-item-meta title="请求头"></t-list-item-meta>
|
||||
</t-list-item>
|
||||
<t-textarea v-model="detail_data.header" :autosize="{ minRows: 3, maxRows: 5 }" readonly/>
|
||||
<t-list-item>
|
||||
<t-list-item-meta title="请求cookies" :description="detail_data.cookies"></t-list-item-meta>
|
||||
<t-list-item-meta title="请求用户浏览器" ></t-list-item-meta>
|
||||
</t-list-item>
|
||||
<t-textarea v-model="detail_data.user_agent" :autosize="{ minRows: 3, maxRows: 5 }" readonly/>
|
||||
<t-list-item>
|
||||
<t-list-item-meta title="请求BODY" :description="detail_data.body"></t-list-item-meta>
|
||||
<t-list-item-meta title="请求cookies" ></t-list-item-meta>
|
||||
</t-list-item>
|
||||
<t-textarea v-model="detail_data.cookies" :autosize="{ minRows: 3, maxRows: 5 }" readonly/>
|
||||
<t-list-item >
|
||||
<t-list-item-meta title="请求BODY" ></t-list-item-meta>
|
||||
</t-list-item>
|
||||
<t-textarea v-model="detail_data.body" :autosize="{ minRows: 3, maxRows: 5 }" readonly/>
|
||||
</t-list>
|
||||
</t-card>
|
||||
<t-button theme="primary" type="button" @click="backPage">返回</t-button>
|
||||
@@ -92,6 +102,9 @@
|
||||
prefix
|
||||
} from '@/config/global';
|
||||
import model from '@/service/service-detail-base';
|
||||
import {
|
||||
wafIPBlockAddApi
|
||||
} from '@/apis/ipblock';
|
||||
|
||||
export default {
|
||||
name: 'WafAttackLogDetail',
|
||||
@@ -135,7 +148,7 @@
|
||||
},
|
||||
methods: {
|
||||
backPage(){
|
||||
history.go(-1)
|
||||
history.go(-1)
|
||||
},
|
||||
getDetail(id) {
|
||||
let that = this
|
||||
@@ -160,6 +173,57 @@
|
||||
console.log(e);
|
||||
})
|
||||
.finally(() => {});
|
||||
},
|
||||
handleAddipblock() {
|
||||
|
||||
if(this.detail_data.host_code==""){
|
||||
this.$message.warning("当前网站不存在");
|
||||
return
|
||||
}
|
||||
let that = this
|
||||
|
||||
|
||||
const confirmDia = this.$dialog.confirm({
|
||||
header: '加入IP黑名单',
|
||||
body: '你确定要加入黑名单IP('+ this.detail_data.src_ip +")么?",
|
||||
confirmBtn: '确定',
|
||||
cancelBtn: '取消',
|
||||
onConfirm: ({ e }) => {
|
||||
//添加黑名单IP
|
||||
let formData = {
|
||||
host_code: this.detail_data.host_code,
|
||||
ip: this.detail_data.src_ip,
|
||||
remarks: '手工增加',
|
||||
};
|
||||
wafIPBlockAddApi({
|
||||
...formData
|
||||
})
|
||||
.then((res) => {
|
||||
let resdata = res
|
||||
console.log(resdata)
|
||||
if (resdata.code === 0) {
|
||||
that.$message.success(resdata.msg);
|
||||
} else {
|
||||
that.$message.warning(resdata.msg);
|
||||
}
|
||||
})
|
||||
.catch((e: Error) => {
|
||||
console.log(e);
|
||||
})
|
||||
.finally(() => {});
|
||||
|
||||
// 请求成功后,销毁弹框
|
||||
confirmDia.destroy();
|
||||
},
|
||||
onClose: ({ e, trigger }) => {
|
||||
console.log('e: ', e);
|
||||
console.log('trigger: ', trigger);
|
||||
confirmDia.hide();
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -162,6 +162,12 @@ export default Vue.extend({
|
||||
ellipsis: true,
|
||||
colKey: 'action',
|
||||
},
|
||||
{
|
||||
title: '响应码',
|
||||
width: 60,
|
||||
ellipsis: false,
|
||||
colKey: 'status_code',
|
||||
},
|
||||
{
|
||||
title: '触发规则',
|
||||
align: 'left',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export const RULE = {
|
||||
is_manual_rule:"1",
|
||||
is_manual_rule:"0",
|
||||
rule_content:"zxcv",
|
||||
rule_base: {
|
||||
salience: 10,
|
||||
|
||||
@@ -83,7 +83,7 @@ func (m *wafSystenService) run() {
|
||||
}
|
||||
|
||||
//初始化本地数据库
|
||||
wafenginecore.InitDb()
|
||||
wafenginecore.InitDb("")
|
||||
|
||||
//初始化队列引擎
|
||||
wafenginecore.InitDequeEngine()
|
||||
|
||||
@@ -61,7 +61,7 @@ func (receiver *WafSystemConfigService) GetDetailByIdApi(id string) model.System
|
||||
}
|
||||
func (receiver *WafSystemConfigService) GetDetailByItem(item string) model.SystemConfig {
|
||||
var bean model.SystemConfig
|
||||
global.GWAF_LOCAL_DB.Where("Item=?", item).Find(&bean)
|
||||
global.GWAF_LOCAL_DB.Debug().Where("Item=?", item).Find(&bean)
|
||||
return bean
|
||||
}
|
||||
func (receiver *WafSystemConfigService) GetListApi(req request.WafSystemConfigSearchReq) ([]model.SystemConfig, int64, error) {
|
||||
|
||||
@@ -10,9 +10,12 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func InitDb() {
|
||||
func InitDb(currentDir string) {
|
||||
if currentDir == "" {
|
||||
currentDir = utils.GetCurrentDir()
|
||||
}
|
||||
if global.GWAF_LOCAL_DB == nil {
|
||||
path := utils.GetCurrentDir() + "/data/local.db"
|
||||
path := currentDir + "/data/local.db"
|
||||
db, err := gorm.Open(sqlite.Open(path), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic("failed to connect database")
|
||||
@@ -50,7 +53,7 @@ func InitDb() {
|
||||
|
||||
}
|
||||
if global.GWAF_LOCAL_LOG_DB == nil {
|
||||
logDB, err := gorm.Open(sqlite.Open(utils.GetCurrentDir()+"/data/local_log.db"), &gorm.Config{})
|
||||
logDB, err := gorm.Open(sqlite.Open(currentDir+"/data/local_log.db"), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic("failed to connect database")
|
||||
}
|
||||
|
||||
@@ -276,6 +276,8 @@ func (waf *WafEngine) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
RULE: "",
|
||||
ACTION: "通过",
|
||||
Day: currentDay,
|
||||
STATUS: "禁止访问",
|
||||
STATUS_CODE: 403,
|
||||
}
|
||||
weblogbean.ACTION = "禁止"
|
||||
global.GQEQUE_LOG_DB.PushBack(weblogbean)
|
||||
@@ -295,6 +297,8 @@ func EchoErrorInfo(w http.ResponseWriter, r *http.Request, weblogbean innerbean.
|
||||
})
|
||||
weblogbean.RULE = ruleName
|
||||
weblogbean.ACTION = "阻止"
|
||||
weblogbean.STATUS = "阻止访问"
|
||||
weblogbean.STATUS_CODE = 403
|
||||
global.GQEQUE_LOG_DB.PushBack(weblogbean)
|
||||
w.Write([]byte("<html><head><title>您的访问被阻止</title></head><body><center><h1>" + blockInfo + "</h1> <br> 访问识别码:<h3>" + weblogbean.REQ_UUID + "</h3></center></body> </html>"))
|
||||
zlog.Debug(ruleName)
|
||||
@@ -353,6 +357,8 @@ func (waf *WafEngine) modifyResponse() func(*http.Response) error {
|
||||
RULE: "",
|
||||
ACTION: "通过",
|
||||
Day: currentDay,
|
||||
STATUS: resp.Status,
|
||||
STATUS_CODE: resp.StatusCode,
|
||||
}
|
||||
|
||||
host := resp.Request.Host
|
||||
@@ -433,6 +439,8 @@ func (waf *WafEngine) modifyResponse() func(*http.Response) error {
|
||||
//TODO 如果是指定URL 或者 IP 不记录日志
|
||||
if !isStaticAssist && !strings.Contains(weblogbean.URL, "index.php/lttshop/task_scheduling/") {
|
||||
weblogbean.ACTION = "放行"
|
||||
weblogbean.STATUS = resp.Status
|
||||
weblogbean.STATUS_CODE = resp.StatusCode
|
||||
global.GQEQUE_LOG_DB.PushBack(weblogbean)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package waftask
|
||||
|
||||
import (
|
||||
"SamWaf/global"
|
||||
"SamWaf/utils/zlog"
|
||||
"SamWaf/wafenginecore"
|
||||
"github.com/spf13/viper"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTaskDeleteHistoryInfo(t *testing.T) {
|
||||
currentPath := "../"
|
||||
config := viper.New()
|
||||
config.AddConfigPath(currentPath + "/conf/") // 文件所在目录
|
||||
config.SetConfigName("config") // 文件名
|
||||
config.SetConfigType("yml") // 文件类型
|
||||
if err := config.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
zlog.Error("找不到配置文件..")
|
||||
} else {
|
||||
zlog.Error("配置文件出错..")
|
||||
}
|
||||
}
|
||||
|
||||
global.GWAF_USER_CODE = config.GetString("user_code") // 读取配置
|
||||
global.GWAF_TENANT_ID = global.GWAF_USER_CODE
|
||||
global.GWAF_LOCAL_SERVER_PORT = config.GetInt("local_port") //读取本地端口
|
||||
global.GWAF_CUSTOM_SERVER_NAME = config.GetString("custom_server_name") //本地服务器其定义名称
|
||||
zlog.Debug(" load ini: ", global.GWAF_USER_CODE)
|
||||
wafenginecore.InitDb(currentPath)
|
||||
TaskDeleteHistoryInfo()
|
||||
}
|
||||
Reference in New Issue
Block a user