Browse Source

fix:无密读文件bug更改

master
刘子旺 7 months ago
parent
commit
4aa837d62e
  1. 2
      godo/files/fs.go
  2. 25
      godo/files/os.go
  3. 12
      godo/files/pwdfile.go

2
godo/files/fs.go

@ -357,7 +357,7 @@ func HandleWriteFile(w http.ResponseWriter, r *http.Request) {
ispwd := GetPwdFlag()
// 没有加密写入明文
if ispwd == 0 {
if !ispwd {
_, err := io.Copy(file, fileContent)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)

25
godo/files/os.go

@ -368,17 +368,20 @@ func GetSalt(r *http.Request) string {
}
// 获取密码标识位,没有添加上
func GetPwdFlag() int {
isPwd, has := libs.GetConfig("isPwd")
if !has {
req := libs.ReqBody{
Name: "isPwd",
Value: 0,
}
libs.SetConfig(req)
libs.SaveConfig()
}
return isPwd.(int)
func GetPwdFlag() bool {
// TODO@lzw:这里有一个bug,ispwd的值存储的是bool类型,但是读取的时候是float64类型,导致无法正确读取
// isPwd, has := libs.GetConfig("isPwd")
// if !has {
// req := libs.ReqBody{
// Name: "isPwd",
// Value: false,
// }
// libs.SetConfig(req)
// libs.SaveConfig()
// return false
// }
// return isPwd.(bool)
return false
}
// 判读一个目录下有没有同名隐藏文件

12
godo/files/pwdfile.go

@ -37,15 +37,15 @@ func HandleReadFile(w http.ResponseWriter, r *http.Request) {
}
// 没有加密 base64明文传输
if hasPwd == 0 {
if !hasPwd {
data := string(fileContent)
if !strings.HasPrefix(data, "link::") {
data = base64.StdEncoding.EncodeToString(fileContent)
}
resp := libs.APIResponse{Message: "success", Data: data}
json.NewEncoder(w).Encode(resp)
return
}
}
// 有加密,先校验密码,再解密
if !CheckFilePwd(fPwd, salt) {
@ -117,9 +117,15 @@ func HandleSetIsPwd(w http.ResponseWriter, r *http.Request) {
isPwd := r.URL.Query().Get("ispwd")
// 0非加密机器 1加密机器
isPwdValue, _ := strconv.Atoi(isPwd)
var isPwdBool bool
if isPwdValue == 0 {
isPwdBool = false
} else {
isPwdBool = true
}
pwdReq := libs.ReqBody{
Name: "isPwd",
Value: isPwdValue,
Value: isPwdBool,
}
libs.SetConfig(pwdReq)
libs.SaveConfig()

Loading…
Cancel
Save