mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2025-12-06 14:59:18 +08:00
feat:资源优化
This commit is contained in:
@@ -2,4 +2,4 @@ SET CGO_ENABLED=1
|
||||
SET GOOS=windows
|
||||
SET GOARCH=amd64
|
||||
SET GIN_MODE=release
|
||||
go build -ldflags="-X SamWaf/global.GWAF_RELEASE=true -X SamWaf/global.GWAF_RELEASE_VERSION_NAME=20231128 -X SamWaf/global.GWAF_RELEASE_VERSION=v1.0.128 -s -w" -o %cd%/release/SamWaf64.exe main.go && %cd%/upx/win64/upx -9 %cd%/release/SamWaf64.exe
|
||||
go build -ldflags="-X SamWaf/global.GWAF_RELEASE=true -X SamWaf/global.GWAF_RELEASE_VERSION_NAME=20240117 -X SamWaf/global.GWAF_RELEASE_VERSION=v1.1.3 -s -w" -o %cd%/release/SamWaf64.exe main.go && %cd%/upx/win64/upx -9 %cd%/release/SamWaf64.exe
|
||||
@@ -2,4 +2,4 @@ SET CGO_ENABLED=1
|
||||
SET GOOS=windows
|
||||
SET GOARCH=amd64
|
||||
SET GIN_MODE=release
|
||||
go build -ldflags="-X SamWaf/global.GWAF_RELEASE=true -X SamWaf/global.GWAF_RELEASE_VERSION_NAME=20230905 -X SamWaf/global.GWAF_RELEASE_VERSION=115 -s -w" -o %cd%/release/SamWaf64.exe main.go
|
||||
go build -ldflags="-X SamWaf/global.GWAF_RELEASE=true -X SamWaf/global.GWAF_RELEASE_VERSION_NAME=20231128 -X SamWaf/global.GWAF_RELEASE_VERSION=v1.0.128 -s -w" -o %cd%/release/SamWaf64.exe main.go
|
||||
@@ -1 +1 @@
|
||||
docker run --rm -v "$PWD":/media/sf_SamWaf -w /media/sf_SamWaf -e CGO_ENABLED=1 -e GOPROXY=https://goproxy.cn,direct golang:1.19 go build -v -ldflags="-X SamWaf/global.GWAF_RELEASE=true -X SamWaf/global.GWAF_RELEASE_VERSION_NAME=20240112 -X SamWaf/global.GWAF_RELEASE_VERSION=v1.1.2 -s -w -extldflags "-static"" -o /media/sf_SamWaf/release/SamWafLinux64 main.go && upx -9 /media/sf_SamWaf/release/SamWafLinux64
|
||||
docker run --rm -v "$PWD":/media/sf_SamWaf -w /media/sf_SamWaf -e CGO_ENABLED=1 -e GOPROXY=https://goproxy.cn,direct golang:1.19 go build -v -ldflags="-X SamWaf/global.GWAF_RELEASE=true -X SamWaf/global.GWAF_RELEASE_VERSION_NAME=20240117 -X SamWaf/global.GWAF_RELEASE_VERSION=v1.1.3 -s -w -extldflags "-static"" -o /media/sf_SamWaf/release/SamWafLinux64 main.go && upx -9 /media/sf_SamWaf/release/SamWafLinux64
|
||||
@@ -1,4 +1,5 @@
|
||||
custom_server_name: LAPTOP-TUSTCG76
|
||||
local_port: 26666
|
||||
notice:
|
||||
isenable: false
|
||||
soft_id: SamWafCom
|
||||
|
||||
BIN
exedata/ip2region.xdb
Normal file
BIN
exedata/ip2region.xdb
Normal file
Binary file not shown.
10
main.go
10
main.go
@@ -16,6 +16,7 @@ import (
|
||||
"SamWaf/wafsnowflake"
|
||||
"SamWaf/waftask"
|
||||
"crypto/tls"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
dlp "github.com/bytedance/godlp"
|
||||
"github.com/go-co-op/gocron"
|
||||
@@ -33,8 +34,11 @@ import (
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
_ "time/tzdata"
|
||||
)
|
||||
|
||||
//go:embed exedata/ip2region.xdb
|
||||
var Ip2regionBytes []byte // 当前目录,解析为[]byte类型
|
||||
// wafSystenService 实现了 service.Service 接口
|
||||
type wafSystenService struct{}
|
||||
|
||||
@@ -64,6 +68,10 @@ func NeverExit(name string, f func()) {
|
||||
// run 是服务的主要逻辑
|
||||
func (m *wafSystenService) run() {
|
||||
|
||||
//初始化步骤[加载ip数据库]
|
||||
// 从嵌入的文件中读取内容
|
||||
|
||||
global.GCACHE_IP_CBUFF = Ip2regionBytes
|
||||
/*// 启动一个 goroutine 来处理信号
|
||||
go func() {
|
||||
// 创建一个通道来接收信号
|
||||
@@ -110,7 +118,7 @@ func (m *wafSystenService) run() {
|
||||
|
||||
zlog.Info(rversion)
|
||||
|
||||
syscall.Setenv("ZONEINFO", utils.GetCurrentDir()+"//data//zoneinfo")
|
||||
//syscall.Setenv("ZONEINFO", utils.GetCurrentDir()+"//data//zoneinfo")
|
||||
|
||||
//守护程序开始
|
||||
//xdaemon.DaemonProcess("GoTest.exe","./logs/damon.log")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
@echo on
|
||||
chcp 65001
|
||||
set currentpath=%cd%
|
||||
set currentversion=v1.1.2
|
||||
set currentdescription=更新了好多内容
|
||||
set currentversion=v1.1.3
|
||||
set currentdescription=更新多项内容,建议升级
|
||||
%currentpath%\setup\go_gen_updatefile\go_gen_updatefile.exe -desc %currentdescription% -o %currentpath%\release\web\samwaf_update -platform windows-amd64 %currentpath%\release\SamWaf64.exe %currentversion%
|
||||
%currentpath%\setup\go_gen_updatefile\go_gen_updatefile.exe -desc %currentdescription% -o %currentpath%\release\web\samwaf_update -platform linux-amd64 %currentpath%\release\SamWafLinux64 %currentversion%
|
||||
2
vue/dist/index.html
vendored
2
vue/dist/index.html
vendored
@@ -6,7 +6,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
<title>SamWaf网站防火墙系统(Web Application Firewall)</title>
|
||||
<script type="module" crossorigin src="./assets/index.60e04564.js"></script>
|
||||
<script type="module" crossorigin src="./assets/index.672175ca.js"></script>
|
||||
<link rel="stylesheet" href="./assets/style.d43ce3b6.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -27,6 +27,13 @@ func InitCoreDb(currentDir string) {
|
||||
if currentDir == "" {
|
||||
currentDir = utils.GetCurrentDir()
|
||||
}
|
||||
// 判断备份目录是否存在,不存在则创建
|
||||
if _, err := os.Stat(currentDir + "/data/"); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(currentDir+"/data/", os.ModePerm); err != nil {
|
||||
zlog.Error("创建data目录失败:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if global.GWAF_LOCAL_DB == nil {
|
||||
path := currentDir + "/data/local.db"
|
||||
// 检查文件是否存在
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/denisbrodbeck/machineid"
|
||||
"github.com/lionsoul2014/ip2region/binding/golang/xdb"
|
||||
"github.com/satori/go.uuid"
|
||||
"github.com/spf13/viper"
|
||||
"go.uber.org/zap"
|
||||
@@ -751,15 +750,9 @@ func (waf *WafEngine) StartWaf() {
|
||||
}
|
||||
|
||||
//初始化步骤[加载ip数据库]
|
||||
var dbPath = utils.GetCurrentDir() + "/data/ip2region.xdb"
|
||||
// 1、从 dbPath 加载整个 xdb 到内存
|
||||
cBuff, err := xdb.LoadContentFromFile(dbPath)
|
||||
if err != nil {
|
||||
zlog.Info("加载ip库错误")
|
||||
zlog.Debug("failed to load content from `%s`: %s\n", dbPath, err)
|
||||
return
|
||||
}
|
||||
global.GCACHE_IP_CBUFF = cBuff
|
||||
// 从嵌入的文件中读取内容
|
||||
|
||||
//global.GCACHE_IP_CBUFF = main.Ip2regionBytes
|
||||
|
||||
//第一步 检测合法性并加入到全局
|
||||
waf.LoadAllHost()
|
||||
@@ -786,14 +779,25 @@ func (waf *WafEngine) LoadAndInitConfig() {
|
||||
1.如果user_code存在就使用本地的user_code
|
||||
2.
|
||||
*/
|
||||
// 判断备份目录是否存在,不存在则创建
|
||||
configDir := utils.GetCurrentDir() + "/conf/"
|
||||
if _, err := os.Stat(configDir); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(configDir, os.ModePerm); err != nil {
|
||||
zlog.Error("创建config目录失败:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
config := viper.New()
|
||||
config.AddConfigPath(utils.GetCurrentDir() + "/conf/") // 文件所在目录
|
||||
config.SetConfigName("config") // 文件名
|
||||
config.SetConfigType("yml") // 文件类型
|
||||
config.AddConfigPath(configDir) // 文件所在目录
|
||||
config.SetConfigName("config") // 文件名
|
||||
config.SetConfigType("yml") // 文件类型
|
||||
|
||||
waf.EngineCurrentStatus = 1
|
||||
if err := config.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
zlog.Error("找不到配置文件..")
|
||||
config.Set("local_port", global.GWAF_LOCAL_SERVER_PORT)
|
||||
err = config.SafeWriteConfig()
|
||||
} else {
|
||||
zlog.Error("配置文件出错..")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user