2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 11:27:17 +08:00

feat: php 8.4

This commit is contained in:
耗子
2024-11-25 01:45:19 +08:00
parent 7d9de56a82
commit 7f61793b36
7 changed files with 33 additions and 42 deletions

View File

@@ -7,6 +7,7 @@ import (
ut "github.com/go-playground/universal-translator"
"github.com/go-playground/validator/v10"
"github.com/go-rat/sessions"
"github.com/go-rat/utils/crypt"
"github.com/knadh/koanf/v2"
"github.com/robfig/cron/v3"
"gorm.io/gorm"
@@ -24,6 +25,7 @@ var (
Cron *cron.Cron
Queue *queue.Queue
Logger *slog.Logger
Crypter crypt.Crypter
)
// 定义面板状态常量

View File

@@ -10,7 +10,7 @@ import (
)
func init() {
php := []uint{74, 80, 81, 82, 83}
php := []uint{74, 80, 81, 82, 83, 84}
for _, version := range php {
apploader.Register(&types.App{
Slug: fmt.Sprintf("php%d", version),

View File

@@ -3,7 +3,6 @@ package biz
import (
"time"
"github.com/go-rat/utils/crypt"
"gorm.io/gorm"
"github.com/TheTNB/panel/internal/app"
@@ -32,12 +31,8 @@ type DatabaseServer struct {
}
func (r *DatabaseServer) BeforeSave(tx *gorm.DB) error {
crypter, err := crypt.NewXChacha20Poly1305([]byte(app.Key))
if err != nil {
return err
}
r.Password, err = crypter.Encrypt([]byte(r.Password))
var err error
r.Password, err = app.Crypter.Encrypt([]byte(r.Password))
if err != nil {
return err
}
@@ -47,12 +42,7 @@ func (r *DatabaseServer) BeforeSave(tx *gorm.DB) error {
}
func (r *DatabaseServer) AfterFind(tx *gorm.DB) error {
crypter, err := crypt.NewXChacha20Poly1305([]byte(app.Key))
if err != nil {
return err
}
password, err := crypter.Decrypt(r.Password)
password, err := app.Crypter.Decrypt(r.Password)
if err == nil {
r.Password = string(password)
}

View File

@@ -3,7 +3,6 @@ package biz
import (
"time"
"github.com/go-rat/utils/crypt"
"gorm.io/gorm"
"github.com/TheTNB/panel/internal/app"
@@ -21,12 +20,8 @@ type DatabaseUser struct {
}
func (r *DatabaseUser) BeforeSave(tx *gorm.DB) error {
crypter, err := crypt.NewXChacha20Poly1305([]byte(app.Key))
if err != nil {
return err
}
r.Password, err = crypter.Encrypt([]byte(r.Password))
var err error
r.Password, err = app.Crypter.Encrypt([]byte(r.Password))
if err != nil {
return err
}
@@ -36,12 +31,7 @@ func (r *DatabaseUser) BeforeSave(tx *gorm.DB) error {
}
func (r *DatabaseUser) AfterFind(tx *gorm.DB) error {
crypter, err := crypt.NewXChacha20Poly1305([]byte(app.Key))
if err != nil {
return err
}
password, err := crypter.Decrypt(r.Password)
password, err := app.Crypter.Decrypt(r.Password)
if err == nil {
r.Password = string(password)
}

View File

@@ -3,7 +3,6 @@ package biz
import (
"time"
"github.com/go-rat/utils/crypt"
"gorm.io/gorm"
"github.com/TheTNB/panel/internal/app"
@@ -23,16 +22,12 @@ type SSH struct {
}
func (r *SSH) BeforeSave(tx *gorm.DB) error {
crypter, err := crypt.NewXChacha20Poly1305([]byte(app.Key))
var err error
r.Config.Key, err = app.Crypter.Encrypt([]byte(r.Config.Key))
if err != nil {
return err
}
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))
r.Config.Password, err = app.Crypter.Encrypt([]byte(r.Config.Password))
if err != nil {
return err
}
@@ -42,16 +37,11 @@ func (r *SSH) BeforeSave(tx *gorm.DB) error {
}
func (r *SSH) AfterFind(tx *gorm.DB) error {
crypter, err := crypt.NewXChacha20Poly1305([]byte(app.Key))
if err != nil {
return err
}
key, err := crypter.Decrypt(r.Config.Key)
key, err := app.Crypter.Decrypt(r.Config.Key)
if err == nil {
r.Config.Key = string(key)
}
password, err := crypter.Decrypt(r.Config.Password)
password, err := app.Crypter.Decrypt(r.Config.Password)
if err == nil {
r.Config.Password = string(password)
}

View File

@@ -18,6 +18,7 @@ func boot() {
initLogger()
initOrm()
runMigrate()
bootCrypter()
}
func BootWeb() {

View File

@@ -0,0 +1,18 @@
package bootstrap
import (
"log"
"github.com/go-rat/utils/crypt"
"github.com/TheTNB/panel/internal/app"
)
func bootCrypter() {
crypter, err := crypt.NewXChacha20Poly1305([]byte(app.Key))
if err != nil {
log.Fatalf("failed to create crypter: %v", err)
}
app.Crypter = crypter
}