|
|
@ -39,17 +39,11 @@ func HandleWriteFile(w http.ResponseWriter, r *http.Request) { |
|
|
|
} |
|
|
|
defer fileContent.Close() |
|
|
|
fileData, err := io.ReadAll(fileContent) |
|
|
|
fmt.Println("表单数据为:", string(fileData)) |
|
|
|
if err != nil { |
|
|
|
libs.HTTPError(w, http.StatusInternalServerError, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
configPwd, ishas := libs.GetConfig("filePwd") |
|
|
|
configPwdStr, ok := configPwd.(string) |
|
|
|
if !ok { |
|
|
|
libs.HTTPError(w, http.StatusInternalServerError, "配置文件密码格式错误") |
|
|
|
return |
|
|
|
} |
|
|
|
if !ishas { |
|
|
|
// 没开启加密,直接明文写入
|
|
|
|
_, err := newFile.Write(fileData) |
|
|
@ -63,8 +57,13 @@ func HandleWriteFile(w http.ResponseWriter, r *http.Request) { |
|
|
|
} |
|
|
|
libs.SuccessMsg(w, "", "文件写入成功") |
|
|
|
return |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 开启加密后,写入加密数据
|
|
|
|
configPwdStr, ok := configPwd.(string) |
|
|
|
if !ok { |
|
|
|
libs.HTTPError(w, http.StatusInternalServerError, "配置文件密码格式错误") |
|
|
|
return |
|
|
|
} |
|
|
|
_, err = newFile.WriteString(fmt.Sprintf("@%s@", configPwdStr)) |
|
|
|
if err != nil { |
|
|
|
libs.HTTPError(w, http.StatusInternalServerError, "密码写入失败") |
|
|
@ -86,6 +85,7 @@ func HandleWriteFile(w http.ResponseWriter, r *http.Request) { |
|
|
|
} |
|
|
|
libs.SuccessMsg(w, "", "文件写入成功") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func HandleReadFile(w http.ResponseWriter, r *http.Request) { |
|
|
|
path := r.URL.Query().Get("path") |
|
|
@ -153,7 +153,7 @@ func HandleReadFile(w http.ResponseWriter, r *http.Request) { |
|
|
|
res := libs.APIResponse{Message: "加密文件读取成功", Data: content} |
|
|
|
json.NewEncoder(w).Encode(res) |
|
|
|
return |
|
|
|
} |
|
|
|
} else { |
|
|
|
// Pwd不为空,Pwd与文件密码做比对
|
|
|
|
if Pwd != filePwd { |
|
|
|
res := libs.APIResponse{Message: "密码错误,请输入正确的密码", Code: -1, Error: "needPwd"} |
|
|
@ -169,6 +169,7 @@ func HandleReadFile(w http.ResponseWriter, r *http.Request) { |
|
|
|
res := libs.APIResponse{Message: "加密文件读取成功", Data: content} |
|
|
|
json.NewEncoder(w).Encode(res) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func HandleSetFilePwd(w http.ResponseWriter, r *http.Request) { |
|
|
|
Pwd := r.Header.Get("Pwd") |
|
|
|