mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2025-12-06 06:58:54 +08:00
@@ -70,3 +70,17 @@ func (w *WafOneKeyModApi) DoOneKeyModifyApi(c *gin.Context) {
|
||||
response.FailWithMessage("修改失败", c)
|
||||
}
|
||||
}
|
||||
func (w *WafOneKeyModApi) RestoreApi(c *gin.Context) {
|
||||
var req request.WafOneKeyModRestoreReq
|
||||
err := c.ShouldBind(&req)
|
||||
if err == nil {
|
||||
err = wafonekey.RestoreOneKeyMod(req.Id)
|
||||
if err != nil {
|
||||
response.FailWithMessage("还原失败 "+err.Error(), c)
|
||||
} else {
|
||||
response.OkWithMessage("还原成功 请重启在宝塔面板上进行Nginx重启", c)
|
||||
}
|
||||
} else {
|
||||
response.FailWithMessage("解析失败", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,5 +12,6 @@ type OneKeyMod struct {
|
||||
FilePath string `json:"file_path"` //文件路径
|
||||
BeforeContent string `json:"before_content"` //修改前内容
|
||||
AfterContent string `json:"after_content"` //修改后内容
|
||||
IsRestore int `json:"is_restore"` //是否还原
|
||||
Remarks string `json:"remarks"` //备注
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package request
|
||||
|
||||
type WafOneKeyModDelReq struct {
|
||||
Id string `json:"id" form:"id"`
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package request
|
||||
|
||||
type WafOneKeyModDetailReq struct {
|
||||
Id string `json:"id" form:"id"`
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package request
|
||||
|
||||
type WafDoOneKeyModReq struct {
|
||||
FilePath string `json:"file_path"` //文件所在路径
|
||||
}
|
||||
20
model/request/waf_onekeymod_req.go
Normal file
20
model/request/waf_onekeymod_req.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package request
|
||||
|
||||
import "SamWaf/model/common/request"
|
||||
|
||||
type WafOneKeyModDelReq struct {
|
||||
Id string `json:"id" form:"id"`
|
||||
}
|
||||
|
||||
type WafOneKeyModRestoreReq struct {
|
||||
Id string `json:"id" form:"id"`
|
||||
}
|
||||
type WafOneKeyModDetailReq struct {
|
||||
Id string `json:"id" form:"id"`
|
||||
}
|
||||
type WafOneKeyModSearchReq struct {
|
||||
request.PageInfo
|
||||
}
|
||||
type WafDoOneKeyModReq struct {
|
||||
FilePath string `json:"file_path"` //文件所在路径
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package request
|
||||
|
||||
import "SamWaf/model/common/request"
|
||||
|
||||
type WafOneKeyModSearchReq struct {
|
||||
request.PageInfo
|
||||
}
|
||||
@@ -15,4 +15,5 @@ func (receiver *OneKeyModRouter) InitOneKeyModRouter(group *gin.RouterGroup) {
|
||||
router.GET("/samwaf/wafhost/onekeymod/detail", api.GetDetailApi)
|
||||
router.POST("/samwaf/wafhost/onekeymod/doModify", api.DoOneKeyModifyApi)
|
||||
router.GET("/samwaf/wafhost/onekeymod/del", api.DelApi)
|
||||
router.GET("/samwaf/wafhost/onekeymod/restore", api.RestoreApi)
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ func OneKeyModifyBt(btSavePath string) (error, string) {
|
||||
FilePath: filePath,
|
||||
BeforeContent: string(beforeContent),
|
||||
AfterContent: string(afterContent),
|
||||
IsRestore: 0,
|
||||
Remarks: "",
|
||||
})
|
||||
successCnt++
|
||||
@@ -112,3 +113,26 @@ func replaceListenPorts(filePath string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 读取 model.OneKeyMod 表中 IsRestore 为 0 的记录,并还原文件
|
||||
func RestoreOneKeyMod(id string) error {
|
||||
var oneKeyMod model.OneKeyMod
|
||||
err := global.GWAF_LOCAL_LOG_DB.Where("id = ?", id).First(&oneKeyMod).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if oneKeyMod.IsRestore == 1 {
|
||||
return errors.New("该记录已还原")
|
||||
}
|
||||
//还原文件
|
||||
err = ioutil.WriteFile(oneKeyMod.FilePath, []byte(oneKeyMod.BeforeContent), 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//更新 IsRestore 为 1
|
||||
global.GWAF_LOCAL_LOG_DB.Model(&model.OneKeyMod{}).Where("id = ?", id).Update("is_restore", 1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user