diff --git a/src/handler/common/util.go b/src/handler/common/util.go index 18d941b0..cd1b627a 100644 --- a/src/handler/common/util.go +++ b/src/handler/common/util.go @@ -66,7 +66,7 @@ func checkMeta(s, database, flag string) string { } func Highlight(s *model.CoreDataSource, isField string, dbName string) []map[string]string { - ps := enc.Decrypt(model.JWT, s.Password) + ps := enc.Decrypt(model.C.General.SecretKey, s.Password) var list []map[string]string db, err := model.NewDBSub(model.DSN{ Username: s.Username, diff --git a/src/handler/fetch/fetch.go b/src/handler/fetch/fetch.go index 0218ca6d..bcd3917b 100644 --- a/src/handler/fetch/fetch.go +++ b/src/handler/fetch/fetch.go @@ -242,7 +242,7 @@ func FetchSQLTest(c yee.Context) (err error) { IP: s.IP, Username: s.Username, Port: s.Port, - Password: enc.Decrypt(model.JWT, s.Password), + Password: enc.Decrypt(model.C.General.SecretKey, s.Password), CA: s.CAFile, Cert: s.Cert, Key: s.KeyFile, diff --git a/src/handler/login/oidcLogin.go b/src/handler/login/oidcLogin.go index f3f1a666..4faeb4a5 100644 --- a/src/handler/login/oidcLogin.go +++ b/src/handler/login/oidcLogin.go @@ -63,7 +63,7 @@ func oidcAuthUrl(c yee.Context) (oidcAuthUrl string, state string) { // 生成 state,state 格式为 hs265签名.当前分钟数 func generateState() string { curMinutes := strconv.FormatInt(time.Now().Unix()/60, 10) - sign, err := jwt.GetSigningMethod("HS256").Sign(curMinutes, []byte(model.JWT)) + sign, err := jwt.GetSigningMethod("HS256").Sign(curMinutes, []byte(model.C.General.SecretKey)) if err != nil { return "" } @@ -77,7 +77,7 @@ func validState(state string) error { sign := split[0] curMinutes := time.Now().Unix() / 60 for i := 0; i < 3; i++ { - err := jwt.GetSigningMethod("HS256").Verify(strconv.FormatInt(curMinutes-int64(i), 10), sign, []byte(model.JWT)) + err := jwt.GetSigningMethod("HS256").Verify(strconv.FormatInt(curMinutes-int64(i), 10), sign, []byte(model.C.General.SecretKey)) if err == nil { return nil } diff --git a/src/handler/manage/db/dbmanage.go b/src/handler/manage/db/dbmanage.go index ffc250c5..e22914d2 100644 --- a/src/handler/manage/db/dbmanage.go +++ b/src/handler/manage/db/dbmanage.go @@ -82,8 +82,8 @@ func ManageDBCreateOrEdit(c yee.Context) (err error) { case "create": return c.JSON(http.StatusOK, SuperCreateSource(&u.DB)) case "test": - if u.DB.Password != "" && enc.Decrypt(model.JWT, u.DB.Password) != "" { - u.DB.Password = enc.Decrypt(model.JWT, u.DB.Password) + if u.DB.Password != "" && enc.Decrypt(model.C.General.SecretKey, u.DB.Password) != "" { + u.DB.Password = enc.Decrypt(model.C.General.SecretKey, u.DB.Password) } return c.JSON(http.StatusOK, SuperTestDBConnect(&u.DB)) } diff --git a/src/handler/manage/db/impl.go b/src/handler/manage/db/impl.go index 7741cf0a..b3f4445b 100644 --- a/src/handler/manage/db/impl.go +++ b/src/handler/manage/db/impl.go @@ -48,8 +48,8 @@ func ConnTest(u *model.CoreDataSource) error { func SuperEditSource(source *model.CoreDataSource) common.Resp { - if source.Password != "" && enc.Decrypt(model.JWT, source.Password) == "" { - model.DB().Model(&model.CoreDataSource{}).Where("source_id =?", source.SourceId).Updates(&model.CoreDataSource{Password: enc.Encrypt(model.JWT, source.Password)}) + if source.Password != "" && enc.Decrypt(model.C.General.SecretKey, source.Password) == "" { + model.DB().Model(&model.CoreDataSource{}).Where("source_id =?", source.SourceId).Updates(&model.CoreDataSource{Password: enc.Encrypt(model.C.General.SecretKey, source.Password)}) } model.DB().Model(&model.CoreDataSource{}).Where("source_id =?", source.SourceId).Updates(map[string]interface{}{ "id_c": source.IDC, @@ -89,7 +89,7 @@ func SuperEditSource(source *model.CoreDataSource) common.Resp { } func SuperCreateSource(source *model.CoreDataSource) common.Resp { - source.Password = enc.Encrypt(model.JWT, source.Password) + source.Password = enc.Encrypt(model.C.General.SecretKey, source.Password) if source.Password != "" { source.SourceId = uuid.New().String() model.DB().Create(source) diff --git a/src/handler/order/audit/impl.go b/src/handler/order/audit/impl.go index 315a0457..3373966c 100644 --- a/src/handler/order/audit/impl.go +++ b/src/handler/order/audit/impl.go @@ -73,7 +73,7 @@ func ExecuteOrder(u *Confirm, user string) common.Resp { IP: source.IP, Port: source.Port, Username: source.Username, - Password: enc.Decrypt(model.JWT, source.Password), + Password: enc.Decrypt(model.C.General.SecretKey, source.Password), CA: source.CAFile, Cert: source.Cert, Key: source.KeyFile, diff --git a/src/handler/personal/query.go b/src/handler/personal/query.go index 0775009f..8cd6734b 100644 --- a/src/handler/personal/query.go +++ b/src/handler/personal/query.go @@ -161,7 +161,7 @@ func SocketQueryResults(c yee.Context) (err error) { core := new(queryCore) var u model.CoreDataSource model.DB().Where("source_id =?", args.SourceId).First(&u) - core.db, err = sqlx.Connect("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/?charset=utf8mb4", u.Username, enc.Decrypt(model.JWT, u.Password), u.IP, u.Port)) + core.db, err = sqlx.Connect("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/?charset=utf8mb4", u.Username, enc.Decrypt(model.C.General.SecretKey, u.Password), u.IP, u.Port)) if err != nil { c.Logger().Error(err) _ = websocket.Message.Send(ws, lib.ToMsg(queryResults{Error: err.Error()})) diff --git a/src/handler/personal/util.go b/src/handler/personal/util.go index 79aa0a2f..f7e531b0 100644 --- a/src/handler/personal/util.go +++ b/src/handler/personal/util.go @@ -35,7 +35,7 @@ func CallAutoTask(order *model.CoreSqlOrder, length int) { IP: source.IP, Port: source.Port, Username: source.Username, - Password: enc.Decrypt(model.JWT, source.Password), + Password: enc.Decrypt(model.C.General.SecretKey, source.Password), Message: model.GloMessage, MaxAffectRows: autoTask.Affectrow, }, &isCall); err != nil { diff --git a/src/lib/jwtAuth.go b/src/lib/jwtAuth.go index c87aba32..834b124a 100644 --- a/src/lib/jwtAuth.go +++ b/src/lib/jwtAuth.go @@ -34,7 +34,7 @@ func JwtAuth(h Token) (t string, err error) { claims["real_name"] = h.RealName claims["is_record"] = h.IsRecord claims["exp"] = time.Now().Add(time.Hour * 8).Unix() - t, err = token.SignedString([]byte(model.JWT)) + t, err = token.SignedString([]byte(model.C.General.SecretKey)) if err != nil { return "", errors.New("JWT Generate Failure") } @@ -52,13 +52,13 @@ func (h *Token) JwtParse(c yee.Context) *Token { func WSTokenIsValid(token string) (bool, error) { t, err := jwt.Parse(token, func(token *jwt.Token) (interface{}, error) { - return []byte(model.JWT), nil + return []byte(model.C.General.SecretKey), nil }) return t.Valid, err } func WsTokenParse(token string) (*jwt.Token, error) { return jwt.Parse(token, func(token *jwt.Token) (interface{}, error) { - return []byte(model.JWT), nil + return []byte(model.C.General.SecretKey), nil }) } diff --git a/src/model/global.go b/src/model/global.go index 46e0839a..892e3fb9 100644 --- a/src/model/global.go +++ b/src/model/global.go @@ -77,8 +77,6 @@ var C Config var DefaultLogger logger.Logger -var JWT = "" - var GloPer CoreGlobalConfiguration var GloLdap Ldap diff --git a/src/model/impl.go b/src/model/impl.go index f62cd086..cbf2e388 100644 --- a/src/model/impl.go +++ b/src/model/impl.go @@ -82,7 +82,7 @@ func (l *ALdap) LdapConnect(user string, pass string, isTest bool) (isOk bool, e } func (s *CoreDataSource) ConnectDB(schema string) (*gorm.DB, error) { - ps := enc.Decrypt(JWT, s.Password) + ps := enc.Decrypt(C.General.SecretKey, s.Password) if ps == "" { return nil, errors.New("连接失败,密码解析错误!") } diff --git a/src/router/router.go b/src/router/router.go index 7808681b..d166754e 100644 --- a/src/router/router.go +++ b/src/router/router.go @@ -83,7 +83,7 @@ func AddRouter(e *yee.Core) { e.GET("/oidc/_token-login", login.OidcLogin) e.GET("/oidc/state", login.OidcState) - r := e.Group("/api/v2", middleware.JWTWithConfig(middleware.JwtConfig{SigningKey: []byte(model.JWT), TokenLookup: []string{yee.HeaderAuthorization, yee.HeaderSecWebSocketProtocol}})) + r := e.Group("/api/v2", middleware.JWTWithConfig(middleware.JwtConfig{SigningKey: []byte(model.C.General.SecretKey), TokenLookup: []string{yee.HeaderAuthorization, yee.HeaderSecWebSocketProtocol}})) r.POST("/chat", fetch.AiChat) r.Restful("/common/:tp", personal.PersonalRestFulAPis()) r.Restful("/dash/:tp", apis.YearningDashApis())