From 7bb8c59cd6a8e72d812b610ccd90cc45209a6cab Mon Sep 17 00:00:00 2001 From: samwaf Date: Mon, 27 Nov 2023 10:56:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BC=98=E5=8C=96=E6=94=BB=E5=87=BB?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build_docker_release_linux.bat | 2 +- localwaf/src/pages/waf/analysis/index.vue | 148 +++-- localwaf/src/pages/waf/attack/index.vue | 777 ++++++++++++---------- localwaf/src/utils/date.ts | 13 +- model/request/waf_attack_log_search.go | 13 +- service/waf_service/waf_log.go | 5 +- vue/dist/index.html | 4 +- 7 files changed, 539 insertions(+), 423 deletions(-) diff --git a/build_docker_release_linux.bat b/build_docker_release_linux.bat index 0197d9e..554eb3a 100644 --- a/build_docker_release_linux.bat +++ b/build_docker_release_linux.bat @@ -1 +1 @@ -docker run --rm -v "$PWD":/media/sf_SamWaf -w /media/sf_SamWaf -e CGO_ENABLED=1 -e GOPROXY=https://goproxy.cn,direct golang:1.19 go build -v -ldflags="-X SamWaf/global.GWAF_RELEASE=true -X SamWaf/global.GWAF_RELEASE_VERSION_NAME=20231126 -X SamWaf/global.GWAF_RELEASE_VERSION=v1.0.125 -s -w -extldflags "-static"" -o /media/sf_SamWaf/release/SamWafLinux64 main.go \ No newline at end of file +docker run --rm -v "$PWD":/media/sf_SamWaf -w /media/sf_SamWaf -e CGO_ENABLED=1 -e GOPROXY=https://goproxy.cn,direct golang:1.19 go build -v -ldflags="-X SamWaf/global.GWAF_RELEASE=true -X SamWaf/global.GWAF_RELEASE_VERSION_NAME=20231127 -X SamWaf/global.GWAF_RELEASE_VERSION=v1.0.126 -s -w -extldflags "-static"" -o /media/sf_SamWaf/release/SamWafLinux64 main.go \ No newline at end of file diff --git a/localwaf/src/pages/waf/analysis/index.vue b/localwaf/src/pages/waf/analysis/index.vue index 6b00c34..b1c8420 100644 --- a/localwaf/src/pages/waf/analysis/index.vue +++ b/localwaf/src/pages/waf/analysis/index.vue @@ -61,74 +61,79 @@ wafanalysisdaycountryrange } from '@/apis/stats'; echarts.use([TooltipComponent, LegendComponent, PieChart, GridComponent, LineChart, CanvasRenderer, MapChart, VisualMapComponent]); -import 'echarts-wordcloud'; + import 'echarts-wordcloud'; export default { name: 'Analysis', data() { return { //词云的相关配置 - wordCloudChartsInfo:{ - wordCloudEchart:null, - wordCloudOptions:{ - series: [{ - type: 'wordCloud', - shape: 'circle', - keepAspect: false, - // maskImage: maskImage, - left: 'center', - top: 'center', - width: '100%', - height: '90%', - right: null, - bottom: null, - sizeRange: [12, 60], - rotationRange: [-90, 90], - rotationStep: 45, - gridSize: 8, - drawOutOfBound: false, - layoutAnimation: true, + wordCloudChartsInfo: { + wordCloudEchart: null, + wordCloudOptions: { + series: [{ + type: 'wordCloud', + shape: 'circle', + keepAspect: false, + // maskImage: maskImage, + left: 'center', + top: 'center', + width: '100%', + height: '90%', + right: null, + bottom: null, + sizeRange: [12, 60], + rotationRange: [-90, 90], + rotationStep: 45, + gridSize: 8, + drawOutOfBound: false, + layoutAnimation: true, + textStyle: { + fontFamily: 'sans-serif', + fontWeight: 'bold', + color: function () { + return 'rgb(' + [ + Math.round(Math.random() * 160), + Math.round(Math.random() * 160), + Math.round(Math.random() * 160) + ].join(',') + ')'; + } + }, + emphasis: { + // focus: 'self', textStyle: { - fontFamily: 'sans-serif', - fontWeight: 'bold', - color: function () { - return 'rgb(' + [ - Math.round(Math.random() * 160), - Math.round(Math.random() * 160), - Math.round(Math.random() * 160) - ].join(',') + ')'; - } - }, - emphasis: { - // focus: 'self', - textStyle: { - textShadowBlur: 3, - textShadowColor: '#333' - } - }, - //data属性中的value值却大,权重就却大,展示字体就却大 - data: [ - //{name: 'Farrah',value: 366}, - //{name: "汽车",value: 900}, - //{name: "视频",value: 606}, - ] + textShadowBlur: 3, + textShadowColor: '#333' + } + }, + //data属性中的value值却大,权重就却大,展示字体就却大 + data: [ + //{name: 'Farrah',value: 366}, + //{name: "汽车",value: 900}, + //{name: "视频",value: 606}, + ] }] - } + } }, currentAction: "", - action_options: [{ - label: '阻止', - value: '阻止' - }, - { - label: '放行', - value: '放行' - }, - { - label: '禁止', - value: '禁止' - }, + action_options: [ + { + label: '全部', + value: '' + }, + { + label: '阻止', + value: '阻止' + }, + { + label: '放行', + value: '放行' + }, + { + label: '禁止', + value: '禁止' + }, ], presets: { 最近7天: [new Date(+new Date() - 86400000 * 6), new Date()], @@ -217,6 +222,11 @@ import 'echarts-wordcloud'; this.initEcharts(); this.loadCountryData(); }, + created() { + this.range1[0] = LAST_7_DAYS[0] + this.range1[1] = LAST_7_DAYS[1] + console.log(this.range1) + }, methods: { renderIcon() { @@ -272,7 +282,7 @@ import 'echarts-wordcloud'; this.initWordCloud(); }, //初始化世界地图 - initWorldMap(){ + initWorldMap() { // /* 融合数据 世界和中国 @@ -313,16 +323,16 @@ import 'echarts-wordcloud'; }); */ }, //初始化词云 - initWordCloud(){ - let that = this - let echartDom = document.getElementById('wordCloudCountry') - that.wordCloudChartsInfo.wordCloudEchart = echarts.init(echartDom) - that.wordCloudChartsInfo.wordCloudEchart.setOption(that.wordCloudChartsInfo.wordCloudOptions) + initWordCloud() { + let that = this + let echartDom = document.getElementById('wordCloudCountry') + that.wordCloudChartsInfo.wordCloudEchart = echarts.init(echartDom) + that.wordCloudChartsInfo.wordCloudEchart.setOption(that.wordCloudChartsInfo.wordCloudOptions) - //随着屏幕大小调节图表 - window.addEventListener("resize", () => { - that.wordCloudChartsInfo.wordCloudEchart.resize(); - }); + //随着屏幕大小调节图表 + window.addEventListener("resize", () => { + that.wordCloudChartsInfo.wordCloudEchart.resize(); + }); }, map_decodePolygon(coordinate, encodeOffsets, encodeScale) { var result = []; @@ -398,7 +408,7 @@ import 'echarts-wordcloud'; width: 80%; height: 100vh; /* 让布局占据整个视口高度 */ - height:50rem; + height: 50rem; } .left-column { @@ -434,4 +444,4 @@ import 'echarts-wordcloud'; /* 下半部分背景色 */ padding: 20px; } - + \ No newline at end of file diff --git a/localwaf/src/pages/waf/attack/index.vue b/localwaf/src/pages/waf/attack/index.vue index 9f30510..f78bba4 100644 --- a/localwaf/src/pages/waf/attack/index.vue +++ b/localwaf/src/pages/waf/attack/index.vue @@ -3,21 +3,14 @@ - + - + {{ item }} @@ -26,50 +19,43 @@ - + - + - + - + + + + + + + + + + - 查询 + 查询 重置 @@ -77,365 +63,470 @@
- + + + -
- + diff --git a/localwaf/src/utils/date.ts b/localwaf/src/utils/date.ts index 39e2a6e..b8131f1 100644 --- a/localwaf/src/utils/date.ts +++ b/localwaf/src/utils/date.ts @@ -5,9 +5,20 @@ export const LAST_7_DAYS = [ dayjs().subtract(7, 'day').format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD'), ]; - + export const LAST_30_DAYS = [ dayjs().subtract(30, 'day').format('YYYY-MM-DD'), dayjs().subtract(1, 'day').format('YYYY-MM-DD'), ]; +//当前日期 +export const NowDate = dayjs().format('YYYY-MM-DD'); + +//转换数据成毫秒 +export function ConvertStringToUnix(timestr: string) :Number{ + return dayjs(timestr).valueOf() +} +//转换字符串 +export function ConvertDateToString(now: Date) :string{ + return dayjs(now).format('YYYY-MM-DD'); +} diff --git a/model/request/waf_attack_log_search.go b/model/request/waf_attack_log_search.go index faca11e..08c15c2 100644 --- a/model/request/waf_attack_log_search.go +++ b/model/request/waf_attack_log_search.go @@ -3,10 +3,13 @@ package request import "SamWaf/model/common/request" type WafAttackLogSearch struct { - HostCode string `json:"host_code" form:"host_code"` //主机码 - Rule string `json:"rule" form:"rule"` //规则名 - Action string `json:"action" form:"action"` //状态 - SrcIp string `json:"src_ip" form:"src_ip"` //请求IP - StatusCode string `json:"status_code" form:"status_code"` //响应码 + HostCode string `json:"host_code" form:"host_code"` //主机码 + Rule string `json:"rule" form:"rule"` //规则名 + Action string `json:"action" form:"action"` //状态 + SrcIp string `json:"src_ip" form:"src_ip"` //请求IP + StatusCode string `json:"status_code" form:"status_code"` //响应码 + UnixAddTimeBegin string `json:"unix_add_time_begin" form:"unix_add_time_begin"` //开始时间 + UnixAddTimeEnd string `json:"unix_add_time_end" form:"unix_add_time_end"` //结束时间 + Method string `json:"method" form:"method"` //访问方法 request.PageInfo } diff --git a/service/waf_service/waf_log.go b/service/waf_service/waf_log.go index b4d0160..c380b57 100644 --- a/service/waf_service/waf_log.go +++ b/service/waf_service/waf_log.go @@ -34,14 +34,15 @@ func (receiver *WafLogService) GetListApi(log request.WafAttackLogSearch) ([]inn Action: log.Action, SrcIp: log.SrcIp, StatusCode: log.StatusCode, + Method: log.Method, PageInfo: request2.PageInfo{ PageIndex: 0, PageSize: 0, Keyword: "", }, } - global.GWAF_LOCAL_LOG_DB.Limit(log.PageSize).Where(whereCondition).Offset(log.PageSize * (log.PageIndex - 1)).Order("create_time desc").Find(&weblogs) - global.GWAF_LOCAL_LOG_DB.Model(&innerbean.WebLog{}).Where(whereCondition).Count(&total) + global.GWAF_LOCAL_LOG_DB.Limit(log.PageSize).Where(whereCondition).Where("unix_add_time>=? and unix_add_time<=?", log.UnixAddTimeBegin, log.UnixAddTimeEnd).Offset(log.PageSize * (log.PageIndex - 1)).Order("create_time desc").Find(&weblogs) + global.GWAF_LOCAL_LOG_DB.Model(&innerbean.WebLog{}).Where(whereCondition).Where("unix_add_time>=? and unix_add_time<=?", log.UnixAddTimeBegin, log.UnixAddTimeEnd).Count(&total) return weblogs, total, nil } func (receiver *WafLogService) GetListByHostCodeApi(log request.WafAttackLogSearch) ([]innerbean.WebLog, int64, error) { diff --git a/vue/dist/index.html b/vue/dist/index.html index e6b766b..a2fd7bb 100644 --- a/vue/dist/index.html +++ b/vue/dist/index.html @@ -6,8 +6,8 @@ Sam网站应用级入侵防御系统后台(Web Application Firewall) - - + +