From 919a79175438fcf4cee2bf482289c19fdbeeaa7f Mon Sep 17 00:00:00 2001 From: samwaf Date: Mon, 15 Jan 2024 10:27:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=A0=B8=E5=BF=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=AF=8F=E6=AC=A1=E9=87=8D=E5=90=AF=E8=BF=9B=E8=A1=8C=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=A4=87=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- localwaf/src/pages/waf/host/index.vue | 8 +----- wafdb/localdb.go | 40 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/localwaf/src/pages/waf/host/index.vue b/localwaf/src/pages/waf/host/index.vue index eb3f74a..ccc2445 100644 --- a/localwaf/src/pages/waf/host/index.vue +++ b/localwaf/src/pages/waf/host/index.vue @@ -670,13 +670,7 @@ let postdata = { ...that.formEditData } - if(postdata.remote_host.length==0){ - postdata.remote_host = "http://"+postdata.host - }else{ - if(postdata.remote_host.startsWith("http://")==false || postdata.remote_host.startsWith("https://")==false ){ - postdata.remote_host = "http://"+postdata.remote_host - } - } + postdata['ssl'] = Number(postdata['ssl']) console.log(postdata) this.$request diff --git a/wafdb/localdb.go b/wafdb/localdb.go index f8f89f8..07db13f 100644 --- a/wafdb/localdb.go +++ b/wafdb/localdb.go @@ -10,7 +10,10 @@ import ( "SamWaf/utils/zlog" "fmt" uuid "github.com/satori/go.uuid" + "io" "net/url" + "os" + "path/filepath" "time" //"github.com/kangarooxin/gorm-plugin-crypto" @@ -25,6 +28,43 @@ func InitCoreDb(currentDir string) { } if global.GWAF_LOCAL_DB == nil { path := currentDir + "/data/local.db" + // 检查文件是否存在 + if _, err := os.Stat(path); !os.IsNotExist(err) { + // 文件存在的逻辑 + backupDir := currentDir + "/data/backups" + // 判断备份目录是否存在,不存在则创建 + if _, err := os.Stat(backupDir); os.IsNotExist(err) { + if err := os.MkdirAll(backupDir, os.ModePerm); err != nil { + zlog.Error("创建备份目录失败:", err) + return + } + } + // 创建备份文件 + backupFilePath := filepath.Join(backupDir, fmt.Sprintf("local_backup_%s.db", time.Now().Format("20060102150405"))) + backupFile, err := os.Create(backupFilePath) + if err != nil { + zlog.Error("创建备份文件失败:", err) + return + } + defer backupFile.Close() + + // 打开原始文件 + originalFile, err := os.Open(path) + if err != nil { + zlog.Error("打开原始文件失败:", err) + return + } + defer originalFile.Close() + + // 复制文件内容到备份文件 + _, err = io.Copy(backupFile, originalFile) + if err != nil { + zlog.Error("文件复制失败:", err) + return + } + + zlog.Info("文件备份成功,备份文件路径:", backupFilePath) + } key := url.QueryEscape(global.GWAF_PWD_COREDB) dns := fmt.Sprintf("%s?_db_key=%s", path, key) db, err := gorm.Open(sqlite.Open(dns), &gorm.Config{})