mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 03:07:20 +08:00
fix: 加解密
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"github.com/TheTNB/panel/internal/app"
|
||||
"github.com/go-rat/utils/crypt"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -30,23 +32,30 @@ type DatabaseServer struct {
|
||||
}
|
||||
|
||||
func (r *DatabaseServer) BeforeSave(tx *gorm.DB) error {
|
||||
// TODO fix
|
||||
/*var err error
|
||||
r.Password, err = app.Crypter.Encrypt([]byte(r.Password))
|
||||
crypter, err := crypt.NewXChacha20Poly1305([]byte(app.Key))
|
||||
if err != nil {
|
||||
return err
|
||||
}*/
|
||||
}
|
||||
|
||||
r.Password, err = crypter.Encrypt([]byte(r.Password))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DatabaseServer) AfterFind(tx *gorm.DB) error {
|
||||
// TODO fix
|
||||
/*password, err := app.Crypter.Decrypt(r.Password)
|
||||
crypter, err := crypt.NewXChacha20Poly1305([]byte(app.Key))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
password, err := crypter.Decrypt(r.Password)
|
||||
if err == nil {
|
||||
r.Password = string(password)
|
||||
}*/
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"github.com/TheTNB/panel/internal/app"
|
||||
"github.com/go-rat/utils/crypt"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -31,23 +33,30 @@ type DatabaseUser struct {
|
||||
}
|
||||
|
||||
func (r *DatabaseUser) BeforeSave(tx *gorm.DB) error {
|
||||
// TODO fix
|
||||
/*var err error
|
||||
r.Password, err = app.Crypter.Encrypt([]byte(r.Password))
|
||||
crypter, err := crypt.NewXChacha20Poly1305([]byte(app.Key))
|
||||
if err != nil {
|
||||
return err
|
||||
}*/
|
||||
}
|
||||
|
||||
r.Password, err = crypter.Encrypt([]byte(r.Password))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DatabaseUser) AfterFind(tx *gorm.DB) error {
|
||||
// TODO fix
|
||||
/*password, err := app.Crypter.Decrypt(r.Password)
|
||||
crypter, err := crypt.NewXChacha20Poly1305([]byte(app.Key))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
password, err := crypter.Decrypt(r.Password)
|
||||
if err == nil {
|
||||
r.Password = string(password)
|
||||
}*/
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"github.com/TheTNB/panel/internal/app"
|
||||
"github.com/go-rat/utils/crypt"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -21,31 +23,38 @@ type SSH struct {
|
||||
}
|
||||
|
||||
func (r *SSH) BeforeSave(tx *gorm.DB) error {
|
||||
// TODO fix
|
||||
/*var err error
|
||||
r.Config.Key, err = app.Crypter.Encrypt([]byte(r.Config.Key))
|
||||
crypter, err := crypt.NewXChacha20Poly1305([]byte(app.Key))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.Config.Password, err = app.Crypter.Encrypt([]byte(r.Config.Password))
|
||||
|
||||
r.Config.Key, err = crypter.Encrypt([]byte(r.Config.Key))
|
||||
if err != nil {
|
||||
return err
|
||||
}*/
|
||||
}
|
||||
r.Config.Password, err = crypter.Encrypt([]byte(r.Config.Password))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *SSH) AfterFind(tx *gorm.DB) error {
|
||||
// TODO fix
|
||||
/*key, err := app.Crypter.Decrypt(r.Config.Key)
|
||||
crypter, err := crypt.NewXChacha20Poly1305([]byte(app.Key))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
key, err := crypter.Decrypt(r.Config.Key)
|
||||
if err == nil {
|
||||
r.Config.Key = string(key)
|
||||
}
|
||||
password, err := app.Crypter.Decrypt(r.Config.Password)
|
||||
password, err := crypter.Decrypt(r.Config.Password)
|
||||
if err == nil {
|
||||
r.Config.Password = string(password)
|
||||
}*/
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@ package bootstrap
|
||||
import "github.com/google/wire"
|
||||
|
||||
// ProviderSet is bootstrap providers.
|
||||
var ProviderSet = wire.NewSet(NewConf, NewLog, NewCli, NewValidator, NewRouter, NewHttp, NewDB, NewMigrate, NewSession, NewCron, NewQueue, NewCrypter)
|
||||
var ProviderSet = wire.NewSet(NewConf, NewLog, NewCli, NewValidator, NewRouter, NewHttp, NewDB, NewMigrate, NewSession, NewCron, NewQueue)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"github.com/go-rat/utils/crypt"
|
||||
"github.com/knadh/koanf/v2"
|
||||
)
|
||||
|
||||
func NewCrypter(conf *koanf.Koanf) (crypt.Crypter, error) {
|
||||
return crypt.NewXChacha20Poly1305([]byte(conf.MustString("app.key")))
|
||||
}
|
||||
Reference in New Issue
Block a user