security:uuid

#247
This commit is contained in:
samwaf
2025-04-08 08:56:08 +08:00
parent c9225ba915
commit 10f28d7472
41 changed files with 162 additions and 101 deletions

View File

@@ -1,6 +1,7 @@
package api
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
@@ -11,7 +12,6 @@ import (
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
"github.com/gin-gonic/gin"
uuid "github.com/satori/go.uuid"
"log"
"net/http"
"os"
@@ -254,7 +254,7 @@ func processImportData(dataType interface{}, tableName string, rows [][]string,
case reflect.String:
if tableName == "hosts" {
if importCodeStrategy == "0" && fieldName == "Code" {
fieldVal.SetString(uuid.NewV4().String())
fieldVal.SetString(uuid.GenUUID())
} else {
fieldVal.SetString(val)
}
@@ -277,7 +277,7 @@ func processImportData(dataType interface{}, tableName string, rows [][]string,
fieldVal := newInstance.Field(fieldIdx)
// 给 BaseOrm 赋值
baseOrm := baseorm.BaseOrm{
Id: uuid.NewV4().String(), // 新生成的 ID
Id: uuid.GenUUID(), // 新生成的 ID
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,6 +1,7 @@
package api
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/enums"
"SamWaf/global"
@@ -14,7 +15,6 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/pquerna/otp/totp"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -70,7 +70,7 @@ func (w *WafLoginApi) LoginApi(c *gin.Context) {
loginError := fmt.Sprintf("输入密码错误超过次数限制IP:%s 归属地区:%s", clientIP, clientCountry)
wafSysLog := model.WafSysLog{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),
@@ -114,7 +114,7 @@ func (w *WafLoginApi) LoginApi(c *gin.Context) {
}
//记录状态
accessToken := utils.Md5String(uuid.NewV4().String())
accessToken := utils.Md5String(uuid.GenUUID())
tokenInfo := wafTokenInfoService.AddApi(bean.LoginAccount, accessToken, c.ClientIP())
//令牌记录到cache里
@@ -129,7 +129,7 @@ func (w *WafLoginApi) LoginApi(c *gin.Context) {
wafSysLog := model.WafSysLog{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,6 +1,7 @@
package api
import (
"SamWaf/common/uuid"
"SamWaf/common/zlog"
"SamWaf/enums"
"SamWaf/global"
@@ -12,7 +13,6 @@ import (
"errors"
"fmt"
"github.com/gin-gonic/gin"
uuid "github.com/satori/go.uuid"
"gorm.io/gorm"
"strings"
)
@@ -31,7 +31,7 @@ func (w *WafRuleAPi) AddApi(c *gin.Context) {
response.FailWithMessage("规则解析错误", c)
return
}
var ruleCode = uuid.NewV4().String()
var ruleCode = uuid.GenUUID()
if req.IsManualRule == 1 {
ruleCodeFormDRL, err := ruleHelper.ExtractRuleName(req.RuleJson)
if err != nil {

View File

@@ -7,7 +7,7 @@ import (
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"SamWaf/common/uuid"
"time"
)
@@ -18,7 +18,7 @@ var Waf{{.EntityName}}ServiceApp = new(Waf{{.EntityName}}Service)
func (receiver *Waf{{.EntityName}}Service) AddApi(req request.Waf{{.EntityName}}AddReq) error {
var bean = &model.{{.EntityName}}{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

9
common/uuid/uuid.go Normal file
View File

@@ -0,0 +1,9 @@
package uuid
import (
uuidnew "github.com/google/uuid"
)
func GenUUID() string {
return uuidnew.NewString()
}

55
common/uuid/uuid_test.go Normal file
View File

@@ -0,0 +1,55 @@
package uuid
import (
"fmt"
"sync"
"testing"
)
func TestGenUUIDConcurrent(t *testing.T) {
// 测试并发情况下生成的 UUID 是否唯一
const goroutines = 10
const countPerGoroutine = 1000
var wg sync.WaitGroup
uuidChan := make(chan string, goroutines*countPerGoroutine)
// 并发生成 UUID
for i := 0; i < goroutines; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for j := 0; j < countPerGoroutine; j++ {
uuidChan <- GenUUID()
}
}()
}
wg.Wait()
close(uuidChan)
// 检查是否有重复
uuids := make(map[string]bool)
for uuid := range uuidChan {
if uuids[uuid] {
t.Errorf("并发测试中发现重复 UUID: %s", uuid)
}
uuids[uuid] = true
}
}
func BenchmarkGenUUID(b *testing.B) {
for i := 0; i < b.N; i++ {
GenUUID()
}
}
func TestGenUUIDList(t *testing.T) {
for i := 0; i < 100; i++ {
// 测试单次生成的 UUID 是否有效
uuid := GenUUID()
fmt.Println(fmt.Sprintf("uuidNew:%s", uuid))
}
}

3
go.mod
View File

@@ -14,6 +14,7 @@ require (
github.com/go-acme/lego/v4 v4.20.4
github.com/go-co-op/gocron v1.17.1
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.0
github.com/hyperjumptech/grule-rule-engine v1.15.0
github.com/kardianos/service v1.2.2
@@ -23,7 +24,6 @@ require (
github.com/samwafgo/ahocorasick v1.0.0
github.com/samwafgo/go-wxsqlite3 v1.0.1
github.com/samwafgo/sqlitedriver v1.0.2
github.com/satori/go.uuid v1.2.0
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0
@@ -70,7 +70,6 @@ require (
github.com/go-playground/validator/v10 v10.23.0 // indirect
github.com/goccy/go-json v0.10.4 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect

2
go.sum
View File

@@ -202,8 +202,6 @@ github.com/samwafgo/go-wxsqlite3 v1.0.1 h1:Jv3IH1zmp2kyFWFRzz6eZGXSWWCGESPneCAge
github.com/samwafgo/go-wxsqlite3 v1.0.1/go.mod h1:Q72tT7m3Twc1yNqJHmwl3nKR26mgFlguzSnxSAFiLJU=
github.com/samwafgo/sqlitedriver v1.0.2 h1:QGQrK+r9z9izEpPAW5MSjhK3vg5H45STLVrAiFT0QJU=
github.com/samwafgo/sqlitedriver v1.0.2/go.mod h1:OtH66Yn4WxfnFA+1VhT2iMYdbKJQgZDExqsDy/1Nz5w=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=

View File

@@ -1,12 +1,12 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -17,7 +17,7 @@ var CenterServiceApp = new(CenterService)
func (receiver *CenterService) AddApi(req request.CenterClientUpdateReq) error {
var bean = &model.Center{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,6 +1,7 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
@@ -8,7 +9,6 @@ import (
"SamWaf/model/request"
"SamWaf/utils"
"errors"
uuid "github.com/satori/go.uuid"
"gorm.io/gorm"
"time"
)
@@ -20,7 +20,7 @@ var WafAccountServiceApp = new(WafAccountService)
func (receiver *WafAccountService) AddApi(req request.WafAccountAddReq) error {
var bean = &model.Account{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -18,7 +18,7 @@ var WafWhiteIpServiceApp = new(WafWhiteIpService)
func (receiver *WafWhiteIpService) AddApi(wafWhiteIpAddReq request.WafAllowIpAddReq) error {
var wafHost = &model.IPAllowList{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -18,7 +18,7 @@ var WafWhiteUrlServiceApp = new(WafWhiteUrlService)
func (receiver *WafWhiteUrlService) AddApi(req request.WafAllowUrlAddReq) error {
var bean = &model.URLAllowList{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -24,7 +24,7 @@ func (receiver *WafAntiCCService) AddApi(req request.WafAntiCCAddReq) error {
}
var bean = &model.AntiCC{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"gorm.io/gorm"
"time"
)
@@ -24,7 +24,7 @@ func (receiver *WafBatchTaskService) AddApi(req request.BatchTaskAddReq) error {
}
var bean = &model.BatchTask{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -18,7 +18,7 @@ var WafBlockIpServiceApp = new(WafBlockIpService)
func (receiver *WafBlockIpService) AddApi(req request.WafBlockIpAddReq) error {
var bean = &model.IPBlockList{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -18,7 +18,7 @@ var WafBlockUrlServiceApp = new(WafBlockUrlService)
func (receiver *WafBlockUrlService) AddApi(req request.WafBlockUrlAddReq) error {
var bean = &model.URLBlockList{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -18,7 +18,7 @@ var WafBlockingPageServiceApp = new(WafBlockingPageService)
func (receiver *WafBlockingPageService) AddApi(req request.WafBlockingPageAddReq) error {
var bean = &model.BlockingPage{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,11 +1,11 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -16,7 +16,7 @@ var WafDelayMsgServiceApp = new(WafDelayMsgService)
func (receiver *WafDelayMsgService) Add(DelayType, DelayTile, DelayContent string) error {
var bean = &model.DelayMsg{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,6 +1,7 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/common/validfield"
"SamWaf/customtype"
"SamWaf/global"
@@ -8,7 +9,6 @@ import (
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"strings"
"time"
)
@@ -20,13 +20,13 @@ var WafHostServiceApp = new(WafHostService)
func (receiver *WafHostService) AddApi(wafHostAddReq request.WafHostAddReq) (string, error) {
uniCode := ""
if wafHostAddReq.Code == "" {
uniCode = uuid.NewV4().String()
uniCode = uuid.GenUUID()
} else {
uniCode = wafHostAddReq.Code
}
var wafHost = &model.Hosts{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -18,7 +18,7 @@ var WafHttpAuthBaseServiceApp = new(WafHttpAuthBaseService)
func (receiver *WafHttpAuthBaseService) AddApi(req request.WafHttpAuthBaseAddReq) error {
var bean = &model.HttpAuthBase{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -18,7 +18,7 @@ var WafLdpUrlServiceApp = new(WafLdpUrlService)
func (receiver *WafLdpUrlService) AddApi(req request.WafLdpUrlAddReq) error {
var bean = &model.LDPUrl{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -18,7 +18,7 @@ var WafLoadBalanceServiceApp = new(WafLoadBalanceService)
func (receiver *WafLoadBalanceService) AddApi(req request.WafLoadBalanceAddReq) error {
var addBean = &model.LoadBalance{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -18,7 +18,7 @@ var WafOtpServiceApp = new(WafOtpService)
func (receiver *WafOtpService) AddApi(req request.WafOtpAddReq) error {
var bean = &model.Otp{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),
@@ -110,7 +110,7 @@ func (receiver *WafOtpService) ModifyApi(req request.WafOtpEditReq) error {
func (receiver *WafOtpService) BindApi(req request.WafOtpBindReq) error {
var bean = &model.Otp{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,6 +1,7 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/common/zlog"
"SamWaf/customtype"
"SamWaf/global"
@@ -8,7 +9,6 @@ import (
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -20,7 +20,7 @@ func (receiver *WafRuleService) AddApi(wafRuleAddReq request.WafRuleAddReq, rule
var wafRule = &model.Rules{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -18,7 +18,7 @@ var WafSensitiveServiceApp = new(WafSensitiveService)
func (receiver *WafSensitiveService) AddApi(req request.WafSensitiveAddReq) error {
var bean = &model.Sensitive{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,6 +1,7 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/common/zlog"
"SamWaf/customtype"
"SamWaf/global"
@@ -13,7 +14,6 @@ import (
"encoding/pem"
"errors"
"fmt"
"github.com/satori/go.uuid"
"gorm.io/gorm"
"path/filepath"
"time"
@@ -57,7 +57,7 @@ func (receiver *WafSslConfigService) AddApi(req request.SslConfigAddReq) error {
}
var bean = &model.SslConfig{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),
@@ -91,7 +91,7 @@ func (receiver *WafSslConfigService) CreateNewIdInner(config model.SslConfig) {
zlog.Info(fmt.Sprintf("%s 证书已经存在不进行再次备份", config.Domains))
return
}
config.Id = uuid.NewV4().String()
config.Id = uuid.GenUUID()
if config.CertPath == "" {
config.CertPath = filepath.Join(utils.GetCurrentDir(), "ssl", config.Id, "domain.crt")
}

View File

@@ -1,6 +1,7 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
@@ -8,7 +9,6 @@ import (
"SamWaf/model/request"
"SamWaf/model/response"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -19,7 +19,7 @@ var WafSslExpireServiceApp = new(WafSslExpireService)
func (receiver *WafSslExpireService) AddApi(req request.WafSslExpireAddReq) error {
var bean = &model.SslExpire{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),
@@ -38,7 +38,7 @@ func (receiver *WafSslExpireService) AddApi(req request.WafSslExpireAddReq) erro
func (receiver *WafSslExpireService) Add(domain string, port int) error {
var bean = &model.SslExpire{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,12 +1,12 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -17,7 +17,7 @@ var WafSSLOrderServiceApp = new(WafSSLOrderService)
func (receiver *WafSSLOrderService) AddApi(req request.WafSslorderaddReq) (model.SslOrder, error) {
var bean = &model.SslOrder{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),
@@ -133,7 +133,7 @@ func (receiver *WafSSLOrderService) RenewAdd(orderId string) (model.SslOrder, er
order := receiver.GetDetailById(orderId)
var bean = &model.SslOrder{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -18,7 +18,7 @@ var WafSystemConfigServiceApp = new(WafSystemConfigService)
func (receiver *WafSystemConfigService) AddApi(wafSystemConfigAddReq request.WafSystemConfigAddReq) error {
var bean = &model.SystemConfig{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"SamWaf/model/request"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -18,7 +18,7 @@ var WafTaskServiceApp = new(WafTaskService)
func (receiver *WafTaskService) AddApi(req request.WafTaskAddReq) error {
var bean = &model.Task{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),
@@ -38,7 +38,7 @@ func (receiver *WafTaskService) AddApi(req request.WafTaskAddReq) error {
func (receiver *WafTaskService) Add(req model.Task) error {
var bean = &model.Task{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,12 +1,12 @@
package waf_service
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"errors"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -18,7 +18,7 @@ func (receiver *WafTokenInfoService) AddApi(loginAccount string, AccessToken str
var bean = &model.TokenInfo{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,11 +1,11 @@
package wafconfig
import (
"SamWaf/common/uuid"
"SamWaf/global"
"SamWaf/utils"
"fmt"
"github.com/denisbrodbeck/machineid"
uuid "github.com/satori/go.uuid"
"github.com/spf13/viper"
"os"
"time"
@@ -45,7 +45,7 @@ func LoadAndInitConfig() {
if config.IsSet("user_code") == false {
id, err := machineid.ID()
if err != nil {
newcode := "RAD" + uuid.NewV4().String()
newcode := "RAD" + uuid.GenUUID()
config.Set("user_code", newcode)
global.GWAF_USER_CODE = newcode
} else {

View File

@@ -1,6 +1,7 @@
package wafdb
import (
"SamWaf/common/uuid"
"SamWaf/common/zlog"
"SamWaf/customtype"
"SamWaf/global"
@@ -11,7 +12,6 @@ import (
"context"
"database/sql"
"fmt"
uuid "github.com/satori/go.uuid"
"gorm.io/gorm/logger"
"io"
"net/url"
@@ -223,7 +223,7 @@ func InitLogDb(currentDir string) {
sharDbBean := model.ShareDb{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,6 +1,7 @@
package wafenginecore
import (
"SamWaf/common/uuid"
"SamWaf/common/zlog"
"SamWaf/customtype"
"SamWaf/enums"
@@ -13,7 +14,6 @@ import (
"SamWaf/utils/ssl"
"errors"
"fmt"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -96,7 +96,7 @@ func (waf *WafEngine) ApplySSLOrder(chanType int, bean model.SslOrder) {
func (waf *WafEngine) processSSL(updateSSLOrder model.SslOrder, bean model.SslOrder) error {
newSslConfig := model.SslConfig{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -2,6 +2,7 @@ package wafcaptcha
import (
"SamWaf/cache"
"SamWaf/common/uuid"
"SamWaf/common/zlog"
"SamWaf/enums"
"SamWaf/global"
@@ -10,7 +11,6 @@ import (
"encoding/json"
"fmt"
"github.com/golang/freetype/truetype"
uuid "github.com/satori/go.uuid"
"github.com/wenlng/go-captcha-assets/bindata/chars"
"github.com/wenlng/go-captcha-assets/resources/fonts/fzshengsksjw"
"github.com/wenlng/go-captcha-assets/resources/images"
@@ -350,7 +350,7 @@ func (s *CaptchaService) GetClickBasicCaptData(w http.ResponseWriter, r *http.Re
}
dotsByte, _ := json.Marshal(dotData)
key := uuid.NewV4().String()
key := uuid.GenUUID()
//key := helper.StringToMD5(string(dotsByte))
s.cache.SetWithTTl(enums.CACHE_CAPTCHA_TRY+key, dotsByte, 1*time.Minute)
@@ -433,7 +433,7 @@ func (s *CaptchaService) VerifyCaptcha(w http.ResponseWriter, r *http.Request, c
if chkRet {
code = 0
// 生成验证通过的标识
captchaPassToken := uuid.NewV4().String()
captchaPassToken := uuid.GenUUID()
// 将标识存入缓存
s.cache.SetWithTTl(enums.CACHE_CAPTCHA_PASS+captchaPassToken+clientIP, "ok", time.Duration(expireTime)*time.Hour)

View File

@@ -2,6 +2,7 @@ package wafenginecore
import (
"SamWaf/common/domaintool"
"SamWaf/common/uuid"
"SamWaf/common/zlog"
"SamWaf/customtype"
"SamWaf/enums"
@@ -22,7 +23,6 @@ import (
"errors"
"fmt"
goahocorasick "github.com/samwafgo/ahocorasick"
"github.com/satori/go.uuid"
"go.uber.org/zap"
"io"
"net"
@@ -197,7 +197,7 @@ func (waf *WafEngine) ServeHTTP(w http.ResponseWriter, r *http.Request) {
CONTENT_LENGTH: contentLength,
COOKIES: string(cookies),
BODY: string(bodyByte),
REQ_UUID: uuid.NewV4().String(),
REQ_UUID: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
HOST_CODE: hostCode,
TenantId: global.GWAF_TENANT_ID,
@@ -476,7 +476,7 @@ func (waf *WafEngine) ServeHTTP(w http.ResponseWriter, r *http.Request) {
CONTENT_LENGTH: contentLength,
COOKIES: string(cookies),
BODY: string(bodyByte),
REQ_UUID: uuid.NewV4().String(),
REQ_UUID: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
HOST_CODE: "",
TenantId: global.GWAF_TENANT_ID,
@@ -805,7 +805,7 @@ func (waf *WafEngine) StartWaf() {
CREATE_TIME: customtype.JsonTime(time.Now()),
UPDATE_TIME: customtype.JsonTime(time.Now()),
},
Code: uuid.NewV4().String(),
Code: uuid.GenUUID(),
Host: "全局网站",
Port: 0,
Ssl: 0,
@@ -836,7 +836,7 @@ func (waf *WafEngine) StartWaf() {
wafSysLog := &model.WafSysLog{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),
@@ -860,7 +860,7 @@ func (waf *WafEngine) CloseWaf() {
}()
wafSysLog := &model.WafSysLog{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),
@@ -956,7 +956,7 @@ func (waf *WafEngine) StartProxyServer(innruntime innerbean.ServerRunTime) {
//TODO 记录如果https 端口被占用的情况 记录日志 且应该推送websocket
wafSysLog := model.WafSysLog{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),
@@ -995,7 +995,7 @@ func (waf *WafEngine) StartProxyServer(innruntime innerbean.ServerRunTime) {
//TODO 记录如果http 端口被占用的情况 记录日志 且应该推送websocket
wafSysLog := model.WafSysLog{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package wafonekey
import (
"SamWaf/common/uuid"
"SamWaf/customtype"
"SamWaf/global"
"SamWaf/model"
"SamWaf/model/baseorm"
"errors"
"fmt"
uuid "github.com/satori/go.uuid"
"io/ioutil"
"path/filepath"
"strconv"
@@ -57,7 +57,7 @@ func OneKeyModifyBt(btSavePath string) (error, string) {
//插入记录
global.GQEQUE_LOG_DB.Enqueue(model.OneKeyMod{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,6 +1,7 @@
package wafqueue
import (
"SamWaf/common/uuid"
"SamWaf/common/zlog"
"SamWaf/enums"
"SamWaf/global"
@@ -9,7 +10,6 @@ import (
"SamWaf/utils"
"SamWaf/wafsec"
"encoding/json"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -44,7 +44,7 @@ func ProcessMessageDequeEngine() {
if ws != nil {
msgBody, _ := json.Marshal(model.MsgDataPacket{
MessageId: uuid.NewV4().String(),
MessageId: uuid.GenUUID(),
MessageType: "命中保护规则",
MessageData: rulemessage.RuleInfo + rulemessage.Ip,
MessageAttach: nil,
@@ -80,7 +80,7 @@ func ProcessMessageDequeEngine() {
if ws != nil {
msgBody, _ := json.Marshal(model.MsgDataPacket{
MessageId: uuid.NewV4().String(),
MessageId: uuid.GenUUID(),
MessageType: operatorMessage.OperaType,
MessageData: operatorMessage.OperaCnt,
MessageAttach: nil,
@@ -108,7 +108,7 @@ func ProcessMessageDequeEngine() {
if ws != nil {
//信息包体进行单独处理
msgBody, _ := json.Marshal(model.MsgDataPacket{
MessageId: uuid.NewV4().String(),
MessageId: uuid.GenUUID(),
MessageType: "导出结果",
MessageData: exportResult.Msg,
MessageAttach: nil,
@@ -138,7 +138,7 @@ func ProcessMessageDequeEngine() {
if ws != nil {
//信息包体进行单独处理
msgBody, _ := json.Marshal(model.MsgDataPacket{
MessageId: uuid.NewV4().String(),
MessageId: uuid.GenUUID(),
MessageType: "升级结果",
MessageData: updatemessage.Msg,
MessageAttach: nil,
@@ -168,7 +168,7 @@ func ProcessMessageDequeEngine() {
if ws != nil {
//信息包体进行单独处理
msgBody, _ := json.Marshal(model.MsgDataPacket{
MessageId: uuid.NewV4().String(),
MessageId: uuid.GenUUID(),
MessageType: "信息通知",
MessageData: updatemessage.Msg,
MessageAttach: nil,

View File

@@ -1,6 +1,7 @@
package waftask
import (
"SamWaf/common/uuid"
"SamWaf/common/zlog"
"SamWaf/customtype"
"SamWaf/global"
@@ -9,7 +10,6 @@ import (
"SamWaf/model/baseorm"
"SamWaf/service/waf_service"
"fmt"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -123,7 +123,7 @@ func TaskCounter() {
if statDay.HostCode == "" {
statDay2 := &model.StatsDay{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),
@@ -169,7 +169,7 @@ func TaskCounter() {
if statDay.HostCode == "" {
statDay2 := &model.StatsIPDay{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),
@@ -218,7 +218,7 @@ func TaskCounter() {
if statDay.HostCode == "" {
statDay2 := &model.StatsIPCityDay{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),
@@ -271,7 +271,7 @@ func TaskCounter() {
if ipTag.IP == "" {
insertIpTag := &model.IPTag{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,6 +1,7 @@
package waftask
import (
"SamWaf/common/uuid"
"SamWaf/common/zlog"
"SamWaf/customtype"
"SamWaf/global"
@@ -10,7 +11,6 @@ import (
"SamWaf/utils"
"SamWaf/wafdb"
"fmt"
uuid "github.com/satori/go.uuid"
"os"
"time"
)
@@ -46,7 +46,7 @@ func TaskShareDbInfo() {
}
sharDbBean := model.ShareDb{
BaseOrm: baseorm.BaseOrm{
Id: uuid.NewV4().String(),
Id: uuid.GenUUID(),
USER_CODE: global.GWAF_USER_CODE,
Tenant_ID: global.GWAF_TENANT_ID,
CREATE_TIME: customtype.JsonTime(time.Now()),

View File

@@ -1,13 +1,13 @@
package waftask
import (
"SamWaf/common/uuid"
"SamWaf/common/zlog"
"SamWaf/global"
"SamWaf/model"
"SamWaf/service/waf_service"
"SamWaf/wafsec"
"encoding/json"
uuid "github.com/satori/go.uuid"
"time"
)
@@ -29,7 +29,7 @@ func TaskDelayInfo() {
cmdType = "RELOAD_PAGE"
}
msgBody, _ := json.Marshal(model.MsgDataPacket{
MessageId: uuid.NewV4().String(),
MessageId: uuid.GenUUID(),
MessageType: msg.DelayType,
MessageData: msg.DelayContent,
MessageAttach: nil,