|
@@ -3,6 +3,7 @@ package web
|
|
import (
|
|
import (
|
|
"backup-x/client"
|
|
"backup-x/client"
|
|
"backup-x/entity"
|
|
"backup-x/entity"
|
|
|
|
+ "backup-x/util"
|
|
"net/http"
|
|
"net/http"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
@@ -10,8 +11,19 @@ import (
|
|
|
|
|
|
// Save 保存
|
|
// Save 保存
|
|
func Save(writer http.ResponseWriter, request *http.Request) {
|
|
func Save(writer http.ResponseWriter, request *http.Request) {
|
|
|
|
+ oldConf, _ := entity.GetConfigCache()
|
|
conf := &entity.Config{}
|
|
conf := &entity.Config{}
|
|
|
|
|
|
|
|
+ conf.EncryptKey = oldConf.EncryptKey
|
|
|
|
+ if conf.EncryptKey == "" {
|
|
|
|
+ encryptKey, err := util.GenerateEncryptKey()
|
|
|
|
+ if err != nil {
|
|
|
|
+ writer.Write([]byte("生成Key失败"))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ conf.EncryptKey = encryptKey
|
|
|
|
+ }
|
|
|
|
+
|
|
// 覆盖以前的配置
|
|
// 覆盖以前的配置
|
|
conf.Username = strings.TrimSpace(request.FormValue("Username"))
|
|
conf.Username = strings.TrimSpace(request.FormValue("Username"))
|
|
conf.Password = request.FormValue("Password")
|
|
conf.Password = request.FormValue("Password")
|
|
@@ -20,6 +32,14 @@ func Save(writer http.ResponseWriter, request *http.Request) {
|
|
writer.Write([]byte("请输入登录用户名/密码"))
|
|
writer.Write([]byte("请输入登录用户名/密码"))
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ if conf.Password != oldConf.Password {
|
|
|
|
+ encryptPasswd, err := util.EncryptByEncryptKey(conf.EncryptKey, conf.Password)
|
|
|
|
+ if err != nil {
|
|
|
|
+ writer.Write([]byte("加密失败"))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ conf.Password = encryptPasswd
|
|
|
|
+ }
|
|
|
|
|
|
forms := request.PostForm
|
|
forms := request.PostForm
|
|
for index, projectName := range forms["ProjectName"] {
|
|
for index, projectName := range forms["ProjectName"] {
|
|
@@ -48,6 +68,15 @@ func Save(writer http.ResponseWriter, request *http.Request) {
|
|
conf.SecretKey = strings.TrimSpace(request.FormValue("SecretKey"))
|
|
conf.SecretKey = strings.TrimSpace(request.FormValue("SecretKey"))
|
|
conf.BucketName = strings.TrimSpace(request.FormValue("BucketName"))
|
|
conf.BucketName = strings.TrimSpace(request.FormValue("BucketName"))
|
|
|
|
|
|
|
|
+ if conf.SecretKey != oldConf.SecretKey {
|
|
|
|
+ secretKey, err := util.EncryptByEncryptKey(conf.EncryptKey, conf.SecretKey)
|
|
|
|
+ if err != nil {
|
|
|
|
+ writer.Write([]byte("加密失败"))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ conf.SecretKey = secretKey
|
|
|
|
+ }
|
|
|
|
+
|
|
// 保存到用户目录
|
|
// 保存到用户目录
|
|
err := conf.SaveConfig()
|
|
err := conf.SaveConfig()
|
|
|
|
|