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