mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2025-12-06 06:58:54 +08:00
refactor:重构日期和封装信息
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SamWaf/customtype"
|
||||
"SamWaf/global"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/baseorm"
|
||||
"SamWaf/model/common/response"
|
||||
"SamWaf/model/request"
|
||||
"errors"
|
||||
@@ -187,10 +189,14 @@ func saveDataToDatabase(name string, rows [][]string) ReturnImportData {
|
||||
err := wafHostService.CheckIsExist(data["host"], data["port"])
|
||||
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
var wafHost = &model.Hosts{
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_id: global.GWAF_TENANT_ID,
|
||||
Code: data["code"],
|
||||
Host: data["host"],
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
Code: data["code"],
|
||||
Host: data["host"],
|
||||
/*Port: data["port"],
|
||||
Ssl: data["ssl"],
|
||||
GUARD_STATUS: data["guard_status"],*/
|
||||
@@ -198,12 +204,10 @@ func saveDataToDatabase(name string, rows [][]string) ReturnImportData {
|
||||
REMOTE_APP: data["remote_app"],
|
||||
Remote_host: data["remote_host"],
|
||||
/*Remote_port: data["remote_port"],*/
|
||||
Remote_ip: data["remote_ip"],
|
||||
Certfile: data["certfile"],
|
||||
Keyfile: data["keyfile"],
|
||||
REMARKS: data["remarks"],
|
||||
CREATE_TIME: time.Now(),
|
||||
UPDATE_TIME: time.Now(),
|
||||
Remote_ip: data["remote_ip"],
|
||||
Certfile: data["certfile"],
|
||||
Keyfile: data["keyfile"],
|
||||
REMARKS: data["remarks"],
|
||||
}
|
||||
port, err := strconv.Atoi(data["port"])
|
||||
if err != nil {
|
||||
|
||||
@@ -22,8 +22,8 @@ func (w *WafLoginApi) LoginApi(c *gin.Context) {
|
||||
accountCount, _ := wafAccountService.GetAccountCountApi()
|
||||
if accountCount == 0 {
|
||||
wafAccountService.AddApi(request.WafAccountAddReq{
|
||||
LoginAccount: "admin",
|
||||
LoginPassword: "admin868",
|
||||
LoginAccount: global.GWAF_DEFAULT_ACCOUNT,
|
||||
LoginPassword: global.GWAF_DEFAULT_ACCOUNT_PWD,
|
||||
Status: 0,
|
||||
Remarks: "密码生成",
|
||||
})
|
||||
|
||||
@@ -40,19 +40,19 @@ func (w *WafWebSocketApi) WebSocketMessageApi(c *gin.Context) {
|
||||
zlog.Debug("无鉴权信息,请检查")
|
||||
return
|
||||
}
|
||||
global.GWebSocket.SetWebSocket(tokenInfo.TenantId+tokenInfo.UserCode+tokenInfo.LoginAccount, ws)
|
||||
global.GWebSocket.SetWebSocket(tokenInfo.BaseOrm.Tenant_ID+tokenInfo.BaseOrm.USER_CODE+tokenInfo.LoginAccount, ws)
|
||||
|
||||
defer func() {
|
||||
websocket := global.GWebSocket.GetWebSocket(tokenInfo.TenantId + tokenInfo.UserCode + tokenInfo.LoginAccount)
|
||||
websocket := global.GWebSocket.GetWebSocket(tokenInfo.BaseOrm.Tenant_ID + tokenInfo.BaseOrm.USER_CODE + tokenInfo.LoginAccount)
|
||||
if websocket != nil {
|
||||
websocket.Close()
|
||||
global.GWebSocket.DelWebSocket(tokenInfo.TenantId + tokenInfo.UserCode + tokenInfo.LoginAccount)
|
||||
global.GWebSocket.DelWebSocket(tokenInfo.BaseOrm.Tenant_ID + tokenInfo.BaseOrm.USER_CODE + tokenInfo.LoginAccount)
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
//读取ws中的数据
|
||||
mt, message, err := global.GWebSocket.GetWebSocket(tokenInfo.TenantId + tokenInfo.UserCode + tokenInfo.LoginAccount).ReadMessage()
|
||||
mt, message, err := global.GWebSocket.GetWebSocket(tokenInfo.BaseOrm.Tenant_ID + tokenInfo.BaseOrm.USER_CODE + tokenInfo.LoginAccount).ReadMessage()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func (w *WafWebSocketApi) WebSocketMessageApi(c *gin.Context) {
|
||||
message = []byte("pong")
|
||||
}
|
||||
//写入ws数据
|
||||
err = global.GWebSocket.GetWebSocket(tokenInfo.TenantId+tokenInfo.UserCode+tokenInfo.LoginAccount).WriteMessage(mt, message)
|
||||
err = global.GWebSocket.GetWebSocket(tokenInfo.BaseOrm.Tenant_ID+tokenInfo.BaseOrm.USER_CODE+tokenInfo.LoginAccount).WriteMessage(mt, message)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
||||
57
customtype/mytime.go
Normal file
57
customtype/mytime.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package customtype
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type JsonTime time.Time
|
||||
|
||||
func (t JsonTime) MarshalJSON() ([]byte, error) {
|
||||
s := fmt.Sprintf(`"%s"`, time.Time(t).Format("2006-01-02 15:04:05"))
|
||||
return []byte(s), nil
|
||||
}
|
||||
|
||||
func (t *JsonTime) UnmarshalJSON(data []byte) error {
|
||||
if data == nil || len(data) <= 1 {
|
||||
dateTime, _ := time.Parse("2006-01-02 15:04:05", "0000-00-00 00:00:00")
|
||||
*t = JsonTime(dateTime)
|
||||
return nil
|
||||
}
|
||||
// 因为实际接收到值是""2018-11-25 20:04:51""格式的,所以这里去除前后各一个"号
|
||||
str := string(data[1 : len(data)-1])
|
||||
st, err := time.Parse("2006-01-02 15:04:05", str)
|
||||
if err == nil {
|
||||
*t = JsonTime(st)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t JsonTime) Value() (driver.Value, error) {
|
||||
tm := time.Time(t)
|
||||
//return tm.Format(constant.TimeLayout), nil
|
||||
return tm, nil
|
||||
}
|
||||
|
||||
func (t *JsonTime) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
switch st := value.(type) {
|
||||
case time.Time:
|
||||
*t = JsonTime(st)
|
||||
case string:
|
||||
tm, err := time.Parse("2006-01-02 15:04:05", st)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*t = JsonTime(tm)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (t *JsonTime) ToPtr() *JsonTime {
|
||||
return t
|
||||
}
|
||||
@@ -85,6 +85,11 @@ var (
|
||||
GWAF_PWD_COREDB = "3Y)(27EtO^tK8Bj~CORE" //加密
|
||||
GWAF_PWD_STATDB = "3Y)(27EtO^tK8Bj~STAT" //加密
|
||||
GWAF_PWD_LOGDB = "3Y)(27EtO^tK8Bj~LOG" //加密
|
||||
|
||||
//默认创建的账户和密码
|
||||
GWAF_DEFAULT_ACCOUNT string = "admin" //默认创建的账户
|
||||
GWAF_DEFAULT_ACCOUNT_PWD string = "admin868" //默认创建的密码
|
||||
|
||||
)
|
||||
|
||||
func GetCurrentVersionInt() int {
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
<title>Sam网站应用级入侵防御系统后台(Web Application Firewall)</title>
|
||||
<title>SamWaf网站防火墙系统(Web Application Firewall)</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
@@ -187,19 +187,19 @@ import {
|
||||
align: 'left',
|
||||
width: 250,
|
||||
ellipsis: true,
|
||||
colKey: 'host_code',
|
||||
colKey: 'host_code',
|
||||
},
|
||||
{
|
||||
title: 'Url',
|
||||
title: '速率',
|
||||
width: 200,
|
||||
ellipsis: true,
|
||||
colKey: 'url',
|
||||
colKey: 'rate',
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
title: '限制次数',
|
||||
width: 200,
|
||||
ellipsis: true,
|
||||
colKey: 'remarks',
|
||||
colKey: 'limit',
|
||||
},
|
||||
{
|
||||
title: '添加时间',
|
||||
@@ -209,7 +209,7 @@ import {
|
||||
},
|
||||
|
||||
{
|
||||
align: 'left',
|
||||
align: 'left',
|
||||
width: 200,
|
||||
colKey: 'op',
|
||||
title: '操作',
|
||||
|
||||
@@ -14,7 +14,7 @@ const CODE = {
|
||||
|
||||
const instance = axios.create({
|
||||
baseURL: API_HOST,
|
||||
timeout: 1000,
|
||||
timeout: 3000,
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
@@ -48,7 +48,7 @@ instance.interceptors.response.use(
|
||||
if (data.code === CODE.REQUEST_SUCCESS) {
|
||||
return data;
|
||||
}else if(data.code === CODE.AUTH_FAILURE){
|
||||
localStorage.clear(); //删除用户信息
|
||||
localStorage.clear(); //删除用户信息
|
||||
console.log("鉴权失败")
|
||||
router.replace({path: '/login'})
|
||||
}
|
||||
|
||||
@@ -1,35 +1,26 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"SamWaf/model/baseorm"
|
||||
)
|
||||
|
||||
type Account struct {
|
||||
Id string `gorm:"primary_key" json:"id"`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID(主要键)
|
||||
LoginAccount string `json:"login_account"` //登录账号
|
||||
LoginPassword string `json:"login_password" crypto:"aes"` //密码md5加密
|
||||
Status int `json:"status"` //状态
|
||||
Remarks string `json:"remarks"` //备注
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
LastUpdateTime time.Time `json:"last_update_time"` //上次更新时间
|
||||
baseorm.BaseOrm
|
||||
LoginAccount string `json:"login_account"` //登录账号
|
||||
LoginPassword string `json:"login_password" crypto:"aes"` //密码md5加密
|
||||
Status int `json:"status"` //状态
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
|
||||
type AccountLog struct {
|
||||
Id string `gorm:"primary_key" json:"id"`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID(主要键)
|
||||
LoginAccount string `json:"login_account"` //登录账号
|
||||
OpType string `json:"op_type"` //操作类型
|
||||
OpContent string `json:"op_content"` //操作内容
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
baseorm.BaseOrm
|
||||
LoginAccount string `json:"login_account"` //登录账号
|
||||
OpType string `json:"op_type"` //操作类型
|
||||
OpContent string `json:"op_content"` //操作内容
|
||||
}
|
||||
type TokenInfo struct {
|
||||
Id string `gorm:"primary_key" json:"id"`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID(主要键)
|
||||
LoginAccount string `json:"login_account"` //登录账号
|
||||
LoginIp string `json:"login_ip"` //登录IP
|
||||
AccessToken string `json:"access_token" crypto:"aes"` //访问码
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
LastUpdateTime time.Time `json:"last_update_time"` //上次更新时间
|
||||
baseorm.BaseOrm
|
||||
LoginAccount string `json:"login_account"` //登录账号
|
||||
LoginIp string `json:"login_ip"` //登录IP
|
||||
AccessToken string `json:"access_token" crypto:"aes"` //访问码
|
||||
}
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"SamWaf/model/baseorm"
|
||||
)
|
||||
|
||||
type AntiCC struct {
|
||||
Id string `gorm:"primary_key" json:"id"`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID(主要键)
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Rate int `json:"rate"` //速率
|
||||
Limit int `json:"limit"` //限制
|
||||
Url string `json:"url"` //保护的url
|
||||
Remarks string `json:"remarks"` //备注
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
LastUpdateTime time.Time `json:"last_update_time"` //上次更新时间
|
||||
baseorm.BaseOrm
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Rate int `json:"rate"` //速率
|
||||
Limit int `json:"limit"` //限制
|
||||
Url string `json:"url"` //保护的url
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
|
||||
15
model/baseorm/baseorm.go
Normal file
15
model/baseorm/baseorm.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package baseorm
|
||||
|
||||
import "SamWaf/customtype"
|
||||
|
||||
/*
|
||||
*
|
||||
base orm
|
||||
*/
|
||||
type BaseOrm struct {
|
||||
Id string `gorm:"primary_key" json:"id"` //
|
||||
USER_CODE string `json:"user_code"` // 用户码(主要键)
|
||||
Tenant_ID string `json:"tenant_id"` //租户ID
|
||||
CREATE_TIME customtype.JsonTime `json:"create_time"` //创建时间
|
||||
UPDATE_TIME customtype.JsonTime `json:"update_time"` //更新时间
|
||||
}
|
||||
@@ -1,25 +1,19 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"SamWaf/model/baseorm"
|
||||
)
|
||||
|
||||
type IPBlockList struct {
|
||||
Id string `gorm:"primary_key" json:"id"`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID(主要键)
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Ip string `json:"ip"` //限制ip
|
||||
Remarks string `json:"remarks"` //备注
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
LastUpdateTime time.Time `json:"last_update_time"` //上次更新时间
|
||||
baseorm.BaseOrm
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Ip string `json:"ip"` //限制ip
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
|
||||
type URLBlockList struct {
|
||||
Id string `gorm:"primary_key" json:"id"`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID(主要键)
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Url string `json:"url"` //限制请求地址
|
||||
Remarks string `json:"remarks"` //备注
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
LastUpdateTime time.Time `json:"last_update_time"` //上次更新时间
|
||||
baseorm.BaseOrm
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Url string `json:"url"` //限制请求地址
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"SamWaf/model/baseorm"
|
||||
)
|
||||
|
||||
/*
|
||||
*
|
||||
延迟信息
|
||||
*/
|
||||
type DelayMsg struct {
|
||||
Id string `gorm:"primary_key" json:"id"`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID(主要键)
|
||||
DelayType string `json:"delay_type"` //操作类型
|
||||
DelayTile string `json:"delay_title"` //操作标题
|
||||
DelayContent string `json:"delay_content"` //操作内容
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
baseorm.BaseOrm
|
||||
DelayType string `json:"delay_type"` //操作类型
|
||||
DelayTile string `json:"delay_title"` //操作标题
|
||||
DelayContent string `json:"delay_content"` //操作内容
|
||||
}
|
||||
|
||||
@@ -1,27 +1,21 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
import "SamWaf/model/baseorm"
|
||||
|
||||
type Hosts struct {
|
||||
Id int `gorm:"primary_key" json:" - "` //
|
||||
USER_CODE string `json:"user_code"`
|
||||
Tenant_id string `json:"tenant_id"` //租户ID
|
||||
Code string `json:"code"` //唯一码
|
||||
Host string `json:"host"` //域名
|
||||
Port int `json:"port"` //端口
|
||||
Ssl int `json:"ssl"` //是否是ssl
|
||||
GUARD_STATUS int `json:"guard_status"` //防御状态
|
||||
REMOTE_SYSTEM string `json:"remote_system"` //是宝塔 phpstudy等
|
||||
REMOTE_APP string `json:"remote_app"` //是什么类型的应用
|
||||
Remote_host string `json:"remote_host"` //远端域名
|
||||
Remote_port int `json:"remote_port"` //远端端口
|
||||
Remote_ip string `json:"remote_ip"` //远端指定IP
|
||||
Certfile string `json:"certfile"` //证书文件
|
||||
Keyfile string `json:"keyfile"` //密钥文件
|
||||
REMARKS string `json:"remarks"` //备注
|
||||
CREATE_TIME time.Time `json:"create_time"` //创建时间
|
||||
UPDATE_TIME time.Time `json:"update_time"` //更新时间
|
||||
GLOBAL_HOST int `json:"global_host"` //默认全局 1 全局 0非全局
|
||||
baseorm.BaseOrm
|
||||
Code string `json:"code"` //唯一码
|
||||
Host string `json:"host"` //域名
|
||||
Port int `json:"port"` //端口
|
||||
Ssl int `json:"ssl"` //是否是ssl
|
||||
GUARD_STATUS int `json:"guard_status"` //防御状态
|
||||
REMOTE_SYSTEM string `json:"remote_system"` //是宝塔 phpstudy等
|
||||
REMOTE_APP string `json:"remote_app"` //是什么类型的应用
|
||||
Remote_host string `json:"remote_host"` //远端域名
|
||||
Remote_port int `json:"remote_port"` //远端端口
|
||||
Remote_ip string `json:"remote_ip"` //远端指定IP
|
||||
Certfile string `json:"certfile"` //证书文件
|
||||
Keyfile string `json:"keyfile"` //密钥文件
|
||||
REMARKS string `json:"remarks"` //备注
|
||||
GLOBAL_HOST int `json:"global_host"` //默认全局 1 全局 0非全局
|
||||
}
|
||||
|
||||
20
model/ldp.go
20
model/ldp.go
@@ -1,21 +1,17 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"SamWaf/model/baseorm"
|
||||
)
|
||||
|
||||
/*
|
||||
*
|
||||
|
||||
隐私处理
|
||||
隐私处理
|
||||
*/
|
||||
type LDPUrl struct {
|
||||
Id string `gorm:"primary_key" json:"id"`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID(主要键)
|
||||
baseorm.BaseOrm
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
//CompareCol string `json:"CompareCol"` //判断字段
|
||||
CompareType string `json:"compare_type"` //判断类型,包含、开始、结束、完全匹配
|
||||
Url string `json:"url"` //请求地址
|
||||
Remarks string `json:"remarks"` //备注
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
LastUpdateTime time.Time `json:"last_update_time"` //上次更新时间
|
||||
CompareType string `json:"compare_type"` //判断类型,包含、开始、结束、完全匹配
|
||||
Url string `json:"url"` //请求地址
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"SamWaf/model/baseorm"
|
||||
)
|
||||
|
||||
type Rules struct {
|
||||
Id int `gorm:"primary_key" json:" - "` //
|
||||
TenantId string `json:"tenant_id"` //
|
||||
HostCode string `json:"host_code"` //主机唯一码
|
||||
RuleCode string `json:"rule_code"` //规则的唯一码
|
||||
RuleName string `json:"rule_name"` //规则名称
|
||||
RuleContent string `json:"rule_content"` //规则内容
|
||||
RuleContentJSON string `json:"rule_content_json"` //规则JSON内容
|
||||
RuleVersionName string `json:"rule_version_name"` //规则版本名
|
||||
RuleVersion int `json:"rule_version"` //规则版本号
|
||||
UserCode string `json:"user_code"` //用户编码
|
||||
IsPublicRule int `json:"is_public_rule"` //是否为公共规则
|
||||
IsManualRule int `json:"is_manual_rule"` //是否为手工写规则 1:手工编写 0 :UI界面形式
|
||||
RuleStatus int `json:"rule_status"` //规则是否开启 1,开启 0,关闭不生效 999 删除
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
LastUpdateTime time.Time `json:"last_update_time"` //上次更新时间
|
||||
baseorm.BaseOrm
|
||||
HostCode string `json:"host_code"` //主机唯一码
|
||||
RuleCode string `json:"rule_code"` //规则的唯一码
|
||||
RuleName string `json:"rule_name"` //规则名称
|
||||
RuleContent string `json:"rule_content"` //规则内容
|
||||
RuleContentJSON string `json:"rule_content_json"` //规则JSON内容
|
||||
RuleVersionName string `json:"rule_version_name"` //规则版本名
|
||||
RuleVersion int `json:"rule_version"` //规则版本号
|
||||
IsPublicRule int `json:"is_public_rule"` //是否为公共规则
|
||||
IsManualRule int `json:"is_manual_rule"` //是否为手工写规则 1:手工编写 0 :UI界面形式
|
||||
RuleStatus int `json:"rule_status"` //规则是否开启 1,开启 0,关闭不生效 999 删除
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"SamWaf/model/baseorm"
|
||||
)
|
||||
|
||||
/*
|
||||
*
|
||||
整体统计
|
||||
*/
|
||||
type StatsTotal struct {
|
||||
//Id int `json:" - "`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID
|
||||
AttackCount int `json:"attack_count"` //攻击数量
|
||||
VisitCount int `json:"visit_count"` //访问数量
|
||||
HistoryAttackCount int `json:"history_attack_count"` //历史攻击数量
|
||||
HistoryVisitCount int `json:"history_visit_count"` //历史访问数量
|
||||
UpdateTime time.Time `json:"update_time"` //更新时间
|
||||
baseorm.BaseOrm
|
||||
AttackCount int `json:"attack_count"` //攻击数量
|
||||
VisitCount int `json:"visit_count"` //访问数量
|
||||
HistoryAttackCount int `json:"history_attack_count"` //历史攻击数量
|
||||
HistoryVisitCount int `json:"history_visit_count"` //历史访问数量
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -22,16 +21,12 @@ type StatsTotal struct {
|
||||
按天统计和不同类型统计
|
||||
*/
|
||||
type StatsDay struct {
|
||||
//Id int `json:" - "`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID(主要键)
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Day int `json:"day"` //年月日(主要键)
|
||||
Host string `json:"host"` //域名
|
||||
Type string `json:"type"` //类型 放行,阻止
|
||||
Count int `json:"count"` //数量
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
LastUpdateTime time.Time `json:"last_update_time"` //上次更新时间
|
||||
baseorm.BaseOrm
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Day int `json:"day"` //年月日(主要键)
|
||||
Host string `json:"host"` //域名
|
||||
Type string `json:"type"` //类型 放行,阻止
|
||||
Count int `json:"count"` //数量
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -39,17 +34,13 @@ type StatsDay struct {
|
||||
按天统计和不同类型统计IP
|
||||
*/
|
||||
type StatsIPDay struct {
|
||||
//Id int `json:" - "`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID(主要键)
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Day int `json:"day"` //年月日(主要键)
|
||||
Host string `json:"host"` //域名
|
||||
IP string `json:"ip"` //ip
|
||||
Type string `json:"type"` //类型 放行,阻止
|
||||
Count int `json:"count"` //数量
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
LastUpdateTime time.Time `json:"last_update_time"` //上次更新时间
|
||||
baseorm.BaseOrm
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Day int `json:"day"` //年月日(主要键)
|
||||
Host string `json:"host"` //域名
|
||||
IP string `json:"ip"` //ip
|
||||
Type string `json:"type"` //类型 放行,阻止
|
||||
Count int `json:"count"` //数量
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -57,19 +48,15 @@ type StatsIPDay struct {
|
||||
按天统计和不同类型统计城市
|
||||
*/
|
||||
type StatsIPCityDay struct {
|
||||
//Id int `json:" - "`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID(主要键)
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Day int `json:"day"` //年月日(主要键)
|
||||
Host string `json:"host"` //域名
|
||||
Country string `json:"country"` //国家
|
||||
Province string `json:"province"` //省份
|
||||
City string `json:"city"` //城市
|
||||
Type string `json:"type"` //类型 放行,阻止
|
||||
Count int `json:"count"` //数量
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
LastUpdateTime time.Time `json:"last_update_time"` //上次更新时间
|
||||
baseorm.BaseOrm
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Day int `json:"day"` //年月日(主要键)
|
||||
Host string `json:"host"` //域名
|
||||
Country string `json:"country"` //国家
|
||||
Province string `json:"province"` //省份
|
||||
City string `json:"city"` //城市
|
||||
Type string `json:"type"` //类型 放行,阻止
|
||||
Count int `json:"count"` //数量
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"SamWaf/model/baseorm"
|
||||
)
|
||||
|
||||
/*
|
||||
*
|
||||
系统配置
|
||||
*/
|
||||
type SystemConfig struct {
|
||||
Id string `gorm:"primary_key" json:"id"`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID(主要键)
|
||||
IsSystem string `json:"is_system"` //是否是系统值
|
||||
Item string `json:"item"`
|
||||
Value string `json:"value"`
|
||||
HashInfo string `json:"hash_info"`
|
||||
Remarks string `json:"remarks"` //备注
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
LastUpdateTime time.Time `json:"last_update_time"` //上次更新时间
|
||||
baseorm.BaseOrm
|
||||
IsSystem string `json:"is_system"` //是否是系统值
|
||||
Item string `json:"item"`
|
||||
Value string `json:"value"`
|
||||
HashInfo string `json:"hash_info"`
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"SamWaf/model/baseorm"
|
||||
)
|
||||
|
||||
type WafSysLog struct {
|
||||
Id string `gorm:"primary_key" json:"id"`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID(主要键)
|
||||
OpType string `json:"op_type"` //操作类型
|
||||
OpContent string `json:"op_content"` //操作内容
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
baseorm.BaseOrm
|
||||
OpType string `json:"op_type"` //操作类型
|
||||
OpContent string `json:"op_content"` //操作内容
|
||||
}
|
||||
|
||||
@@ -1,26 +1,19 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"SamWaf/model/baseorm"
|
||||
)
|
||||
|
||||
type IPWhiteList struct {
|
||||
Id string `gorm:"primary_key" json:"id"`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID(主要键)
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Ip string `json:"ip"` //白名单ip
|
||||
Remarks string `json:"remarks"` //备注
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
LastUpdateTime time.Time `json:"last_update_time"` //上次更新时间
|
||||
baseorm.BaseOrm
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
Ip string `json:"ip"` //白名单ip
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
|
||||
type URLWhiteList struct {
|
||||
Id string `gorm:"primary_key" json:"id"`
|
||||
UserCode string `json:"user_code"` //用户码(主要键)
|
||||
TenantId string `json:"tenant_id"` //租户ID(主要键)
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
CompareType string `json:"compare_type"` //判断类型,包含、开始、结束、完全匹配
|
||||
Url string `json:"url"` //请求地址
|
||||
Remarks string `json:"remarks"` //备注
|
||||
CreateTime time.Time `json:"create_time"` //创建时间
|
||||
LastUpdateTime time.Time `json:"last_update_time"` //上次更新时间
|
||||
baseorm.BaseOrm
|
||||
HostCode string `json:"host_code"` //网站唯一码(主要键)
|
||||
CompareType string `json:"compare_type"` //判断类型,包含、开始、结束、完全匹配
|
||||
Url string `json:"url"` //请求地址
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package waf_service
|
||||
|
||||
import (
|
||||
"SamWaf/customtype"
|
||||
"SamWaf/global"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/baseorm"
|
||||
"SamWaf/model/request"
|
||||
"errors"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
@@ -15,15 +17,17 @@ var WafAccountServiceApp = new(WafAccountService)
|
||||
|
||||
func (receiver *WafAccountService) AddApi(req request.WafAccountAddReq) error {
|
||||
var bean = &model.Account{
|
||||
Id: uuid.NewV4().String(),
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
TenantId: global.GWAF_TENANT_ID,
|
||||
LoginAccount: req.LoginAccount,
|
||||
LoginPassword: req.LoginPassword,
|
||||
Status: req.Status,
|
||||
Remarks: req.Remarks,
|
||||
CreateTime: time.Now(),
|
||||
LastUpdateTime: time.Now(),
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
LoginAccount: req.LoginAccount,
|
||||
LoginPassword: req.LoginPassword,
|
||||
Status: req.Status,
|
||||
Remarks: req.Remarks,
|
||||
}
|
||||
global.GWAF_LOCAL_DB.Create(bean)
|
||||
return nil
|
||||
@@ -39,11 +43,11 @@ func (receiver *WafAccountService) ModifyApi(req request.WafAccountEditReq) erro
|
||||
return errors.New("当前数据已经存在")
|
||||
}
|
||||
beanMap := map[string]interface{}{
|
||||
"LoginAccount": req.LoginAccount,
|
||||
"LoginPassword": req.LoginPassword,
|
||||
"Status": req.Status,
|
||||
"Remarks": req.Remarks,
|
||||
"last_update_time": time.Now(),
|
||||
"LoginAccount": req.LoginAccount,
|
||||
"LoginPassword": req.LoginPassword,
|
||||
"Status": req.Status,
|
||||
"Remarks": req.Remarks,
|
||||
"UPDATE_TIME": customtype.JsonTime(time.Now()),
|
||||
}
|
||||
err := global.GWAF_LOCAL_DB.Model(model.Account{}).Where("id = ?", req.Id).Updates(beanMap).Error
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package waf_service
|
||||
|
||||
import (
|
||||
"SamWaf/customtype"
|
||||
"SamWaf/global"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/baseorm"
|
||||
"SamWaf/model/request"
|
||||
"errors"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
@@ -15,16 +17,18 @@ var WafAntiCCServiceApp = new(WafAntiCCService)
|
||||
|
||||
func (receiver *WafAntiCCService) AddApi(req request.WafAntiCCAddReq) error {
|
||||
var bean = &model.AntiCC{
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
TenantId: global.GWAF_TENANT_ID,
|
||||
Id: uuid.NewV4().String(),
|
||||
HostCode: req.HostCode,
|
||||
Rate: req.Rate,
|
||||
Limit: req.Limit,
|
||||
Url: req.Url,
|
||||
Remarks: req.Remarks,
|
||||
CreateTime: time.Now(),
|
||||
LastUpdateTime: time.Now(),
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
HostCode: req.HostCode,
|
||||
Rate: req.Rate,
|
||||
Limit: req.Limit,
|
||||
Url: req.Url,
|
||||
Remarks: req.Remarks,
|
||||
}
|
||||
global.GWAF_LOCAL_DB.Create(bean)
|
||||
return nil
|
||||
@@ -42,12 +46,12 @@ func (receiver *WafAntiCCService) ModifyApi(req request.WafAntiCCEditReq) error
|
||||
return errors.New("当前网站和url已经存在")
|
||||
}
|
||||
ipWhiteMap := map[string]interface{}{
|
||||
"Host_Code": req.HostCode,
|
||||
"Url": req.Url,
|
||||
"Rate": req.Rate,
|
||||
"Limit": req.Limit,
|
||||
"Remarks": req.Remarks,
|
||||
"last_update_time": time.Now(),
|
||||
"Host_Code": req.HostCode,
|
||||
"Url": req.Url,
|
||||
"Rate": req.Rate,
|
||||
"Limit": req.Limit,
|
||||
"Remarks": req.Remarks,
|
||||
"UPDATE_TIME": customtype.JsonTime(time.Now()),
|
||||
}
|
||||
err := global.GWAF_LOCAL_DB.Model(model.AntiCC{}).Where("id = ?", req.Id).Updates(ipWhiteMap).Error
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package waf_service
|
||||
|
||||
import (
|
||||
"SamWaf/customtype"
|
||||
"SamWaf/global"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/baseorm"
|
||||
"SamWaf/model/request"
|
||||
"errors"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
@@ -15,14 +17,16 @@ var WafBlockIpServiceApp = new(WafBlockIpService)
|
||||
|
||||
func (receiver *WafBlockIpService) AddApi(req request.WafBlockIpAddReq) error {
|
||||
var bean = &model.IPBlockList{
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
TenantId: global.GWAF_TENANT_ID,
|
||||
Id: uuid.NewV4().String(),
|
||||
HostCode: req.HostCode,
|
||||
Ip: req.Ip,
|
||||
Remarks: req.Remarks,
|
||||
CreateTime: time.Now(),
|
||||
LastUpdateTime: time.Now(),
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
HostCode: req.HostCode,
|
||||
Ip: req.Ip,
|
||||
Remarks: req.Remarks,
|
||||
}
|
||||
global.GWAF_LOCAL_DB.Create(bean)
|
||||
return nil
|
||||
@@ -40,10 +44,10 @@ func (receiver *WafBlockIpService) ModifyApi(req request.WafBlockIpEditReq) erro
|
||||
return errors.New("当前网站和IP已经存在")
|
||||
}
|
||||
ipWhiteMap := map[string]interface{}{
|
||||
"Host_Code": req.HostCode,
|
||||
"Ip": req.Ip,
|
||||
"Remarks": req.Remarks,
|
||||
"last_update_time": time.Now(),
|
||||
"Host_Code": req.HostCode,
|
||||
"Ip": req.Ip,
|
||||
"Remarks": req.Remarks,
|
||||
"UPDATE_TIME": customtype.JsonTime(time.Now()),
|
||||
}
|
||||
err := global.GWAF_LOCAL_DB.Model(model.IPBlockList{}).Where("id = ?", req.Id).Updates(ipWhiteMap).Error
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package waf_service
|
||||
|
||||
import (
|
||||
"SamWaf/customtype"
|
||||
"SamWaf/global"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/baseorm"
|
||||
"SamWaf/model/request"
|
||||
"errors"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
@@ -15,14 +17,16 @@ var WafBlockUrlServiceApp = new(WafBlockUrlService)
|
||||
|
||||
func (receiver *WafBlockUrlService) AddApi(req request.WafBlockUrlAddReq) error {
|
||||
var bean = &model.URLBlockList{
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
TenantId: global.GWAF_TENANT_ID,
|
||||
Id: uuid.NewV4().String(),
|
||||
HostCode: req.HostCode,
|
||||
Url: req.Url,
|
||||
Remarks: req.Remarks,
|
||||
CreateTime: time.Now(),
|
||||
LastUpdateTime: time.Now(),
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
HostCode: req.HostCode,
|
||||
Url: req.Url,
|
||||
Remarks: req.Remarks,
|
||||
}
|
||||
global.GWAF_LOCAL_DB.Create(bean)
|
||||
return nil
|
||||
@@ -40,10 +44,10 @@ func (receiver *WafBlockUrlService) ModifyApi(req request.WafBlockUrlEditReq) er
|
||||
return errors.New("当前网站和url已经存在")
|
||||
}
|
||||
modfiyMap := map[string]interface{}{
|
||||
"Host_Code": req.HostCode,
|
||||
"Url": req.Url,
|
||||
"Remarks": req.Remarks,
|
||||
"last_update_time": time.Now(),
|
||||
"Host_Code": req.HostCode,
|
||||
"Url": req.Url,
|
||||
"Remarks": req.Remarks,
|
||||
"UPDATE_TIME": customtype.JsonTime(time.Now()),
|
||||
}
|
||||
err := global.GWAF_LOCAL_DB.Model(model.URLBlockList{}).Where("id = ?", req.Id).Updates(modfiyMap).Error
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package waf_service
|
||||
|
||||
import (
|
||||
"SamWaf/customtype"
|
||||
"SamWaf/global"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/baseorm"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"time"
|
||||
)
|
||||
@@ -13,13 +15,16 @@ var WafDelayMsgServiceApp = new(WafDelayMsgService)
|
||||
|
||||
func (receiver *WafDelayMsgService) Add(DelayType, DelayTile, DelayContent string) error {
|
||||
var bean = &model.DelayMsg{
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
TenantId: global.GWAF_TENANT_ID,
|
||||
Id: uuid.NewV4().String(),
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
DelayType: DelayType,
|
||||
DelayTile: DelayTile,
|
||||
DelayContent: DelayContent,
|
||||
CreateTime: time.Now(),
|
||||
}
|
||||
global.GWAF_LOCAL_DB.Create(bean)
|
||||
return nil
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package waf_service
|
||||
|
||||
import (
|
||||
"SamWaf/customtype"
|
||||
"SamWaf/global"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/baseorm"
|
||||
"SamWaf/model/request"
|
||||
"errors"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
@@ -15,8 +17,13 @@ var WafHostServiceApp = new(WafHostService)
|
||||
|
||||
func (receiver *WafHostService) AddApi(wafHostAddReq request.WafHostAddReq) (string, error) {
|
||||
var wafHost = &model.Hosts{
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_id: global.GWAF_TENANT_ID,
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
Code: uuid.NewV4().String(),
|
||||
Host: wafHostAddReq.Host,
|
||||
Port: wafHostAddReq.Port,
|
||||
@@ -30,8 +37,6 @@ func (receiver *WafHostService) AddApi(wafHostAddReq request.WafHostAddReq) (str
|
||||
Certfile: wafHostAddReq.Certfile,
|
||||
Keyfile: wafHostAddReq.Keyfile,
|
||||
REMARKS: wafHostAddReq.REMARKS,
|
||||
CREATE_TIME: time.Now(),
|
||||
UPDATE_TIME: time.Now(),
|
||||
}
|
||||
global.GWAF_LOCAL_DB.Create(wafHost)
|
||||
return wafHost.Code, nil
|
||||
@@ -47,7 +52,7 @@ func (receiver *WafHostService) CheckIsExist(host string, port string) error {
|
||||
func (receiver *WafHostService) ModifyApi(wafHostEditReq request.WafHostEditReq) error {
|
||||
var webHost model.Hosts
|
||||
global.GWAF_LOCAL_DB.Where("host = ? and port= ?", wafHostEditReq.Host, wafHostEditReq.Port).Find(&webHost)
|
||||
if webHost.Id != 0 && webHost.Code != wafHostEditReq.CODE {
|
||||
if webHost.Id != "" && webHost.Code != wafHostEditReq.CODE {
|
||||
return errors.New("当前网站和端口已经存在")
|
||||
}
|
||||
if webHost.GLOBAL_HOST == 1 {
|
||||
@@ -67,7 +72,7 @@ func (receiver *WafHostService) ModifyApi(wafHostEditReq request.WafHostEditReq)
|
||||
|
||||
"Certfile": wafHostEditReq.Certfile,
|
||||
"Keyfile": wafHostEditReq.Keyfile,
|
||||
"UPDATE_TIME": time.Now(),
|
||||
"UPDATE_TIME": customtype.JsonTime(time.Now()),
|
||||
}
|
||||
err := global.GWAF_LOCAL_DB.Model(model.Hosts{}).Where("CODE=?", wafHostEditReq.CODE).Updates(hostMap).Error
|
||||
|
||||
@@ -88,6 +93,7 @@ func (receiver *WafHostService) GetListApi(wafHostSearchReq request.WafHostSearc
|
||||
var total int64 = 0
|
||||
global.GWAF_LOCAL_DB.Limit(wafHostSearchReq.PageSize).Offset(wafHostSearchReq.PageSize * (wafHostSearchReq.PageIndex - 1)).Order("global_host desc").Find(&webHosts)
|
||||
global.GWAF_LOCAL_DB.Model(&model.Hosts{}).Count(&total)
|
||||
|
||||
return webHosts, total, nil
|
||||
}
|
||||
func (receiver *WafHostService) DelHostApi(req request.WafHostDelReq) error {
|
||||
@@ -119,7 +125,7 @@ func (receiver *WafHostService) DelHostApi(req request.WafHostDelReq) error {
|
||||
func (receiver *WafHostService) ModifyGuardStatusApi(req request.WafHostGuardStatusReq) error {
|
||||
hostMap := map[string]interface{}{
|
||||
"GUARD_STATUS": req.GUARD_STATUS,
|
||||
"UPDATE_TIME": time.Now(),
|
||||
"UPDATE_TIME": customtype.JsonTime(time.Now()),
|
||||
}
|
||||
|
||||
err := global.GWAF_LOCAL_DB.Model(model.Hosts{}).Where("CODE=?", req.CODE).Updates(hostMap).Error
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package waf_service
|
||||
|
||||
import (
|
||||
"SamWaf/customtype"
|
||||
"SamWaf/global"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/baseorm"
|
||||
"SamWaf/model/request"
|
||||
"errors"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
@@ -15,15 +17,17 @@ var WafLdpUrlServiceApp = new(WafLdpUrlService)
|
||||
|
||||
func (receiver *WafLdpUrlService) AddApi(req request.WafLdpUrlAddReq) error {
|
||||
var bean = &model.LDPUrl{
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
TenantId: global.GWAF_TENANT_ID,
|
||||
Id: uuid.NewV4().String(),
|
||||
HostCode: req.HostCode,
|
||||
CompareType: req.CompareType,
|
||||
Url: req.Url,
|
||||
Remarks: req.Remarks,
|
||||
CreateTime: time.Now(),
|
||||
LastUpdateTime: time.Now(),
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
HostCode: req.HostCode,
|
||||
CompareType: req.CompareType,
|
||||
Url: req.Url,
|
||||
Remarks: req.Remarks,
|
||||
}
|
||||
global.GWAF_LOCAL_DB.Create(bean)
|
||||
return nil
|
||||
@@ -41,11 +45,11 @@ func (receiver *WafLdpUrlService) ModifyApi(req request.WafLdpUrlEditReq) error
|
||||
return errors.New("当前网站和url已经存在")
|
||||
}
|
||||
ipWhiteMap := map[string]interface{}{
|
||||
"Host_Code": req.HostCode,
|
||||
"Url": req.Url,
|
||||
"Remarks": req.Remarks,
|
||||
"Compare_Type": req.CompareType,
|
||||
"last_update_time": time.Now(),
|
||||
"Host_Code": req.HostCode,
|
||||
"Url": req.Url,
|
||||
"Remarks": req.Remarks,
|
||||
"Compare_Type": req.CompareType,
|
||||
"UPDATE_TIME": customtype.JsonTime(time.Now()),
|
||||
}
|
||||
err := global.GWAF_LOCAL_DB.Model(model.LDPUrl{}).Where("id = ?", req.Id).Updates(ipWhiteMap).Error
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package waf_service
|
||||
|
||||
import (
|
||||
"SamWaf/customtype"
|
||||
"SamWaf/global"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/baseorm"
|
||||
"SamWaf/model/request"
|
||||
"SamWaf/utils/zlog"
|
||||
"errors"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -14,8 +17,15 @@ type WafRuleService struct{}
|
||||
var WafRuleServiceApp = new(WafRuleService)
|
||||
|
||||
func (receiver *WafRuleService) AddApi(wafRuleAddReq request.WafRuleAddReq, ruleCode string, chsName string, hostCode string, ruleContent string) error {
|
||||
|
||||
var wafRule = &model.Rules{
|
||||
TenantId: global.GWAF_TENANT_ID,
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
HostCode: hostCode, //网站CODE
|
||||
RuleCode: ruleCode,
|
||||
RuleName: chsName,
|
||||
@@ -23,14 +33,11 @@ func (receiver *WafRuleService) AddApi(wafRuleAddReq request.WafRuleAddReq, rule
|
||||
RuleContentJSON: wafRuleAddReq.RuleJson, //TODO 后续考虑是否应该再从结构转一次
|
||||
RuleVersionName: "初版",
|
||||
RuleVersion: 1,
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
IsPublicRule: 0,
|
||||
IsManualRule: wafRuleAddReq.IsManualRule,
|
||||
RuleStatus: 1,
|
||||
CreateTime: time.Now(),
|
||||
LastUpdateTime: time.Now(),
|
||||
}
|
||||
global.GWAF_LOCAL_DB.Create(wafRule)
|
||||
global.GWAF_LOCAL_DB.Debug().Create(wafRule)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -41,7 +48,7 @@ func (receiver *WafRuleService) AddApi(wafRuleAddReq request.WafRuleAddReq, rule
|
||||
*/
|
||||
func (receiver *WafRuleService) CheckIsExistApi(ruleName string, hostCode string) int64 {
|
||||
var count int64 = 0
|
||||
err := global.GWAF_LOCAL_DB.Model(&model.Rules{}).Where("rule_name = ? and host_code = ? and rule_status<> 999", ruleName, hostCode).Count(&count)
|
||||
err := global.GWAF_LOCAL_DB.Model(&model.Rules{}).Where("rule_name = ? and host_code = ? and rule_status<> 999", ruleName, hostCode).Count(&count).Error
|
||||
if err != nil {
|
||||
zlog.Error("检查是否存在错误", err)
|
||||
}
|
||||
@@ -54,7 +61,7 @@ func (receiver *WafRuleService) ModifyApi(wafRuleEditReq request.WafRuleEditReq,
|
||||
global.GWAF_LOCAL_DB.Where("rule_name = ? and host_code= ?",
|
||||
chsName, hostCode).Find(&rule)
|
||||
|
||||
if rule.Id != 0 && rule.RuleCode != wafRuleEditReq.CODE {
|
||||
if rule.Id != "" && rule.RuleCode != wafRuleEditReq.CODE {
|
||||
|
||||
return errors.New("当前规则名称已经存在")
|
||||
}
|
||||
@@ -72,8 +79,7 @@ func (receiver *WafRuleService) ModifyApi(wafRuleEditReq request.WafRuleEditReq,
|
||||
"IsPublicRule": 0,
|
||||
"IsManualRule": wafRuleEditReq.IsManualRule,
|
||||
"RuleStatus": "1",
|
||||
"LastUpdateTime": time.Now(),
|
||||
//"UPDATE_TIME": time.Now(),
|
||||
"UPDATE_TIME": customtype.JsonTime(time.Now()),
|
||||
}
|
||||
err := global.GWAF_LOCAL_DB.Model(model.Rules{}).Where("rule_code=?", wafRuleEditReq.CODE).Updates(ruleMap).Error
|
||||
|
||||
@@ -93,10 +99,8 @@ func (receiver *WafRuleService) GetListApi(wafRuleSearchReq request.WafRuleSearc
|
||||
var total int64 = 0
|
||||
var rules []model.Rules
|
||||
global.GWAF_LOCAL_DB.Where("rule_status= 1").Limit(wafRuleSearchReq.PageSize).Offset(wafRuleSearchReq.PageSize * (wafRuleSearchReq.PageIndex - 1)).Find(&rules)
|
||||
err := global.GWAF_LOCAL_DB.Where("rule_status= 1 ").Model(&model.Rules{}).Count(&total)
|
||||
if err != nil {
|
||||
zlog.Debug("列查询", err)
|
||||
}
|
||||
global.GWAF_LOCAL_DB.Where("rule_status= 1 ").Model(&model.Rules{}).Count(&total)
|
||||
|
||||
return rules, total, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package waf_service
|
||||
|
||||
import (
|
||||
"SamWaf/customtype"
|
||||
"SamWaf/global"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/baseorm"
|
||||
"SamWaf/model/request"
|
||||
"errors"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
@@ -15,16 +17,18 @@ var WafSystemConfigServiceApp = new(WafSystemConfigService)
|
||||
|
||||
func (receiver *WafSystemConfigService) AddApi(wafSystemConfigAddReq request.WafSystemConfigAddReq) error {
|
||||
var bean = &model.SystemConfig{
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
TenantId: global.GWAF_TENANT_ID,
|
||||
Id: uuid.NewV4().String(),
|
||||
Item: wafSystemConfigAddReq.Item,
|
||||
Value: wafSystemConfigAddReq.Value,
|
||||
IsSystem: "0",
|
||||
Remarks: wafSystemConfigAddReq.Remarks,
|
||||
HashInfo: "",
|
||||
CreateTime: time.Now(),
|
||||
LastUpdateTime: time.Now(),
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
Item: wafSystemConfigAddReq.Item,
|
||||
Value: wafSystemConfigAddReq.Value,
|
||||
IsSystem: "0",
|
||||
Remarks: wafSystemConfigAddReq.Remarks,
|
||||
HashInfo: "",
|
||||
}
|
||||
global.GWAF_LOCAL_DB.Create(bean)
|
||||
return nil
|
||||
@@ -40,10 +44,10 @@ func (receiver *WafSystemConfigService) ModifyApi(req request.WafSystemConfigEdi
|
||||
return errors.New("当前配置已经存在")
|
||||
}
|
||||
editMap := map[string]interface{}{
|
||||
"Item": req.Item,
|
||||
"Value": req.Value,
|
||||
"Remarks": req.Remarks,
|
||||
"last_update_time": time.Now(),
|
||||
"Item": req.Item,
|
||||
"Value": req.Value,
|
||||
"Remarks": req.Remarks,
|
||||
"UPDATE_TIME": customtype.JsonTime(time.Now()),
|
||||
}
|
||||
err := global.GWAF_LOCAL_DB.Model(model.SystemConfig{}).Where("id = ?", req.Id).Updates(editMap).Error
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package waf_service
|
||||
|
||||
import (
|
||||
"SamWaf/customtype"
|
||||
"SamWaf/global"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/baseorm"
|
||||
"errors"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"time"
|
||||
@@ -15,14 +17,16 @@ var WafTokenInfoServiceApp = new(WafTokenInfoService)
|
||||
func (receiver *WafTokenInfoService) AddApi(loginAccount string, AccessToken string, LoginIp string) *model.TokenInfo {
|
||||
|
||||
var bean = &model.TokenInfo{
|
||||
Id: uuid.NewV4().String(),
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
TenantId: global.GWAF_TENANT_ID,
|
||||
LoginAccount: loginAccount,
|
||||
AccessToken: AccessToken,
|
||||
LoginIp: LoginIp,
|
||||
CreateTime: time.Now(),
|
||||
LastUpdateTime: time.Now(),
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
LoginAccount: loginAccount,
|
||||
AccessToken: AccessToken,
|
||||
LoginIp: LoginIp,
|
||||
}
|
||||
global.GWAF_LOCAL_DB.Create(bean)
|
||||
mod := receiver.GetInfoByLoginAccount(loginAccount)
|
||||
@@ -39,8 +43,8 @@ func (receiver *WafTokenInfoService) ModifyApi(loginAccount string, AccessToken
|
||||
return errors.New("当前数据不存在")
|
||||
}
|
||||
beanMap := map[string]interface{}{
|
||||
"login_ip": LoginIp,
|
||||
"last_update_time": time.Now(),
|
||||
"login_ip": LoginIp,
|
||||
"UPDATE_TIME": customtype.JsonTime(time.Now()),
|
||||
}
|
||||
err := global.GWAF_LOCAL_DB.Model(model.Account{}).Where("login_account = ? ,access_token = ? ", loginAccount, AccessToken).Updates(beanMap).Error
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package waf_service
|
||||
|
||||
import (
|
||||
"SamWaf/customtype"
|
||||
"SamWaf/global"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/baseorm"
|
||||
"SamWaf/model/request"
|
||||
"errors"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
@@ -15,14 +17,16 @@ var WafWhiteIpServiceApp = new(WafWhiteIpService)
|
||||
|
||||
func (receiver *WafWhiteIpService) AddApi(wafWhiteIpAddReq request.WafWhiteIpAddReq) error {
|
||||
var wafHost = &model.IPWhiteList{
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
TenantId: global.GWAF_TENANT_ID,
|
||||
Id: uuid.NewV4().String(),
|
||||
HostCode: wafWhiteIpAddReq.HostCode,
|
||||
Ip: wafWhiteIpAddReq.Ip,
|
||||
Remarks: wafWhiteIpAddReq.Remarks,
|
||||
CreateTime: time.Now(),
|
||||
LastUpdateTime: time.Now(),
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
HostCode: wafWhiteIpAddReq.HostCode,
|
||||
Ip: wafWhiteIpAddReq.Ip,
|
||||
Remarks: wafWhiteIpAddReq.Remarks,
|
||||
}
|
||||
global.GWAF_LOCAL_DB.Create(wafHost)
|
||||
return nil
|
||||
@@ -40,10 +44,10 @@ func (receiver *WafWhiteIpService) ModifyApi(wafWhiteIpEditReq request.WafWhiteI
|
||||
return errors.New("当前网站和IP已经存在")
|
||||
}
|
||||
ipWhiteMap := map[string]interface{}{
|
||||
"Host_Code": wafWhiteIpEditReq.HostCode,
|
||||
"Ip": wafWhiteIpEditReq.Ip,
|
||||
"Remarks": wafWhiteIpEditReq.Remarks,
|
||||
"last_update_time": time.Now(),
|
||||
"Host_Code": wafWhiteIpEditReq.HostCode,
|
||||
"Ip": wafWhiteIpEditReq.Ip,
|
||||
"Remarks": wafWhiteIpEditReq.Remarks,
|
||||
"UPDATE_TIME": customtype.JsonTime(time.Now()),
|
||||
}
|
||||
err := global.GWAF_LOCAL_DB.Model(model.IPWhiteList{}).Where("id = ?", wafWhiteIpEditReq.Id).Updates(ipWhiteMap).Error
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package waf_service
|
||||
|
||||
import (
|
||||
"SamWaf/customtype"
|
||||
"SamWaf/global"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/baseorm"
|
||||
"SamWaf/model/request"
|
||||
"errors"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
@@ -15,15 +17,17 @@ var WafWhiteUrlServiceApp = new(WafWhiteUrlService)
|
||||
|
||||
func (receiver *WafWhiteUrlService) AddApi(req request.WafWhiteUrlAddReq) error {
|
||||
var bean = &model.URLWhiteList{
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
TenantId: global.GWAF_TENANT_ID,
|
||||
Id: uuid.NewV4().String(),
|
||||
HostCode: req.HostCode,
|
||||
CompareType: req.CompareType,
|
||||
Url: req.Url,
|
||||
Remarks: req.Remarks,
|
||||
CreateTime: time.Now(),
|
||||
LastUpdateTime: time.Now(),
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
HostCode: req.HostCode,
|
||||
CompareType: req.CompareType,
|
||||
Url: req.Url,
|
||||
Remarks: req.Remarks,
|
||||
}
|
||||
global.GWAF_LOCAL_DB.Create(bean)
|
||||
return nil
|
||||
@@ -41,11 +45,11 @@ func (receiver *WafWhiteUrlService) ModifyApi(req request.WafWhiteUrlEditReq) er
|
||||
return errors.New("当前网站和url已经存在")
|
||||
}
|
||||
ipWhiteMap := map[string]interface{}{
|
||||
"Host_Code": req.HostCode,
|
||||
"Compare_Type": req.CompareType,
|
||||
"Url": req.Url,
|
||||
"Remarks": req.Remarks,
|
||||
"last_update_time": time.Now(),
|
||||
"Host_Code": req.HostCode,
|
||||
"Compare_Type": req.CompareType,
|
||||
"Url": req.Url,
|
||||
"Remarks": req.Remarks,
|
||||
"UPDATE_TIME": customtype.JsonTime(time.Now()),
|
||||
}
|
||||
err := global.GWAF_LOCAL_DB.Model(model.URLWhiteList{}).Where("id = ?", req.Id).Updates(ipWhiteMap).Error
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package wafenginecore
|
||||
|
||||
import (
|
||||
"SamWaf/customtype"
|
||||
"SamWaf/global"
|
||||
"SamWaf/innerbean"
|
||||
"SamWaf/libinjection-go"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/baseorm"
|
||||
"SamWaf/model/wafenginmodel"
|
||||
"SamWaf/plugin"
|
||||
"SamWaf/utils"
|
||||
@@ -669,8 +671,12 @@ func (waf *WafEngine) StartWaf() {
|
||||
if hosts != nil && len(hosts) == 0 {
|
||||
//初始化全局保护
|
||||
var wafGlobalHost = &model.Hosts{
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_id: global.GWAF_TENANT_ID,
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
Code: uuid.NewV4().String(),
|
||||
Host: "全局网站",
|
||||
Port: 0,
|
||||
@@ -683,8 +689,6 @@ func (waf *WafEngine) StartWaf() {
|
||||
Certfile: "",
|
||||
Keyfile: "",
|
||||
REMARKS: "",
|
||||
CREATE_TIME: time.Now(),
|
||||
UPDATE_TIME: time.Now(),
|
||||
GLOBAL_HOST: 1,
|
||||
}
|
||||
global.GWAF_LOCAL_DB.Create(wafGlobalHost)
|
||||
@@ -705,12 +709,15 @@ func (waf *WafEngine) StartWaf() {
|
||||
waf.LoadAllHost()
|
||||
|
||||
wafSysLog := &model.WafSysLog{
|
||||
Id: uuid.NewV4().String(),
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
TenantId: global.GWAF_TENANT_ID,
|
||||
OpType: "信息",
|
||||
OpContent: "WAF启动",
|
||||
CreateTime: time.Now(),
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
OpType: "信息",
|
||||
OpContent: "WAF启动",
|
||||
}
|
||||
global.GQEQUE_LOG_DB.PushBack(wafSysLog)
|
||||
|
||||
@@ -784,12 +791,15 @@ func (waf *WafEngine) CloseWaf() {
|
||||
}
|
||||
}()
|
||||
wafSysLog := &model.WafSysLog{
|
||||
Id: uuid.NewV4().String(),
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
TenantId: global.GWAF_TENANT_ID,
|
||||
OpType: "信息",
|
||||
OpContent: "WAF关闭",
|
||||
CreateTime: time.Now(),
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
OpType: "信息",
|
||||
OpContent: "WAF关闭",
|
||||
}
|
||||
global.GQEQUE_LOG_DB.PushBack(wafSysLog)
|
||||
waf.EngineCurrentStatus = 0
|
||||
@@ -954,12 +964,15 @@ func (waf *WafEngine) StartProxyServer(innruntime innerbean.ServerRunTime) {
|
||||
} else {
|
||||
//TODO 记录如果https 端口被占用的情况 记录日志 且应该推送websocket
|
||||
wafSysLog := model.WafSysLog{
|
||||
Id: uuid.NewV4().String(),
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
TenantId: global.GWAF_TENANT_ID,
|
||||
OpType: "系统运行错误",
|
||||
OpContent: "HTTPS端口被占用: " + strconv.Itoa(innruntime.Port) + ",请检查",
|
||||
CreateTime: time.Time{},
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
OpType: "系统运行错误",
|
||||
OpContent: "HTTPS端口被占用: " + strconv.Itoa(innruntime.Port) + ",请检查",
|
||||
}
|
||||
global.GQEQUE_LOG_DB.PushBack(wafSysLog)
|
||||
zlog.Error("[HTTPServer] https server start fail, cause:[%v]", err)
|
||||
@@ -989,12 +1002,15 @@ func (waf *WafEngine) StartProxyServer(innruntime innerbean.ServerRunTime) {
|
||||
} else {
|
||||
//TODO 记录如果http 端口被占用的情况 记录日志 且应该推送websocket
|
||||
wafSysLog := model.WafSysLog{
|
||||
Id: uuid.NewV4().String(),
|
||||
UserCode: global.GWAF_USER_CODE,
|
||||
TenantId: global.GWAF_TENANT_ID,
|
||||
OpType: "系统运行错误",
|
||||
OpContent: "HTTP端口被占用: " + strconv.Itoa(innruntime.Port) + ",请检查",
|
||||
CreateTime: time.Time{},
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
OpType: "系统运行错误",
|
||||
OpContent: "HTTP端口被占用: " + strconv.Itoa(innruntime.Port) + ",请检查",
|
||||
}
|
||||
global.GQEQUE_LOG_DB.PushBack(wafSysLog)
|
||||
zlog.Error("[HTTPServer] http server start fail, cause:[%v]", err)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package waftask
|
||||
|
||||
import (
|
||||
"SamWaf/customtype"
|
||||
"SamWaf/global"
|
||||
"SamWaf/innerbean"
|
||||
"SamWaf/model"
|
||||
"SamWaf/model/baseorm"
|
||||
"SamWaf/model/request"
|
||||
"SamWaf/service/waf_service"
|
||||
"SamWaf/utils/zlog"
|
||||
@@ -91,21 +93,24 @@ func TaskCounter() {
|
||||
|
||||
if statDay.HostCode == "" {
|
||||
statDay2 := &model.StatsDay{
|
||||
UserCode: value.UserCode,
|
||||
TenantId: value.TenantId,
|
||||
HostCode: value.HostCode,
|
||||
Day: value.Day,
|
||||
Host: value.Host,
|
||||
Type: value.ACTION,
|
||||
Count: value.Count,
|
||||
CreateTime: time.Now(),
|
||||
LastUpdateTime: time.Now(),
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
HostCode: value.HostCode,
|
||||
Day: value.Day,
|
||||
Host: value.Host,
|
||||
Type: value.ACTION,
|
||||
Count: value.Count,
|
||||
}
|
||||
global.GQEQUE_STATS_DB.PushBack(statDay2)
|
||||
} else {
|
||||
statDayMap := map[string]interface{}{
|
||||
"Count": value.Count + statDay.Count,
|
||||
"last_update_time": currenyDayBak,
|
||||
"Count": value.Count + statDay.Count,
|
||||
"UPDATE_TIME": customtype.JsonTime(currenyDayBak),
|
||||
}
|
||||
updateBean := innerbean.UpdateModel{
|
||||
Model: model.StatsDay{},
|
||||
@@ -134,22 +139,25 @@ func TaskCounter() {
|
||||
|
||||
if statDay.HostCode == "" {
|
||||
statDay2 := &model.StatsIPDay{
|
||||
UserCode: value.UserCode,
|
||||
TenantId: value.TenantId,
|
||||
HostCode: value.HostCode,
|
||||
Day: value.Day,
|
||||
Host: value.Host,
|
||||
Type: value.ACTION,
|
||||
Count: value.Count,
|
||||
IP: value.Ip,
|
||||
CreateTime: time.Now(),
|
||||
LastUpdateTime: time.Now(),
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
HostCode: value.HostCode,
|
||||
Day: value.Day,
|
||||
Host: value.Host,
|
||||
Type: value.ACTION,
|
||||
Count: value.Count,
|
||||
IP: value.Ip,
|
||||
}
|
||||
global.GQEQUE_STATS_DB.PushBack(statDay2)
|
||||
} else {
|
||||
statDayMap := map[string]interface{}{
|
||||
"Count": value.Count + statDay.Count,
|
||||
"last_update_time": currenyDayBak,
|
||||
"Count": value.Count + statDay.Count,
|
||||
"UPDATE_TIME": customtype.JsonTime(currenyDayBak),
|
||||
}
|
||||
|
||||
updateBean := innerbean.UpdateModel{
|
||||
@@ -180,24 +188,27 @@ func TaskCounter() {
|
||||
|
||||
if statDay.HostCode == "" {
|
||||
statDay2 := &model.StatsIPCityDay{
|
||||
UserCode: value.UserCode,
|
||||
TenantId: value.TenantId,
|
||||
HostCode: value.HostCode,
|
||||
Day: value.Day,
|
||||
Host: value.Host,
|
||||
Type: value.ACTION,
|
||||
Count: value.Count,
|
||||
Country: value.Country,
|
||||
Province: value.Province,
|
||||
City: value.City,
|
||||
CreateTime: time.Now(),
|
||||
LastUpdateTime: time.Now(),
|
||||
BaseOrm: baseorm.BaseOrm{
|
||||
Id: uuid.NewV4().String(),
|
||||
USER_CODE: global.GWAF_USER_CODE,
|
||||
Tenant_ID: global.GWAF_TENANT_ID,
|
||||
CREATE_TIME: customtype.JsonTime(time.Now()),
|
||||
UPDATE_TIME: customtype.JsonTime(time.Now()),
|
||||
},
|
||||
HostCode: value.HostCode,
|
||||
Day: value.Day,
|
||||
Host: value.Host,
|
||||
Type: value.ACTION,
|
||||
Count: value.Count,
|
||||
Country: value.Country,
|
||||
Province: value.Province,
|
||||
City: value.City,
|
||||
}
|
||||
global.GQEQUE_STATS_DB.PushBack(statDay2)
|
||||
} else {
|
||||
statDayMap := map[string]interface{}{
|
||||
"Count": value.Count + statDay.Count,
|
||||
"last_update_time": currenyDayBak,
|
||||
"Count": value.Count + statDay.Count,
|
||||
"UPDATE_TIME": customtype.JsonTime(currenyDayBak),
|
||||
}
|
||||
|
||||
updateBean := innerbean.UpdateModel{
|
||||
|
||||
Reference in New Issue
Block a user