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

feat: 修改模型

This commit is contained in:
耗子
2024-06-14 22:52:05 +08:00
parent 7a4a71f0a0
commit cc6a45b127
14 changed files with 95 additions and 129 deletions

View File

@@ -11,8 +11,8 @@ type CertStore struct {
Domains []string `form:"domains" json:"domains"`
AutoRenew bool `form:"auto_renew" json:"auto_renew"`
UserID uint `form:"user_id" json:"user_id"`
DNSID *uint `form:"dns_id" json:"dns_id"`
WebsiteID *uint `form:"website_id" json:"website_id"`
DNSID uint `form:"dns_id" json:"dns_id"`
WebsiteID uint `form:"website_id" json:"website_id"`
}
func (r *CertStore) Authorize(ctx http.Context) error {

View File

@@ -12,8 +12,8 @@ type CertUpdate struct {
Domains []string `form:"domains" json:"domains"`
AutoRenew bool `form:"auto_renew" json:"auto_renew"`
UserID uint `form:"user_id" json:"user_id"`
DNSID *uint `form:"dns_id" json:"dns_id"`
WebsiteID *uint `form:"website_id" json:"website_id"`
DNSID uint `form:"dns_id" json:"dns_id"`
WebsiteID uint `form:"website_id" json:"website_id"`
}
func (r *CertUpdate) Authorize(ctx http.Context) error {

View File

@@ -1,22 +1,20 @@
package models
import (
"github.com/goravel/framework/support/carbon"
"github.com/goravel/framework/database/orm"
)
type Cert struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"default:null" json:"user_id"` // 关联的 ACME 用户 ID
WebsiteID *uint `gorm:"default:null" json:"website_id"` // 关联的网站 ID
DNSID *uint `gorm:"column:dns_id;default:null" json:"dns_id"` // 关联的 DNS ID
Type string `gorm:"not null" json:"type"` // 证书类型 (P256, P384, 2048, 4096)
Domains []string `gorm:"type:json;serializer:json" json:"domains"`
AutoRenew bool `gorm:"default:true" json:"auto_renew"` // 自动续签
CertURL *string `gorm:"default:null" json:"cert_url"` // 证书 URL (续签时使用)
Cert string `gorm:"default:null" json:"cert"` // 证书内容
Key string `gorm:"default:null" json:"key"` // 私钥内容
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
UserID uint `gorm:"not null" json:"user_id"` // 关联的 ACME 用户 ID
WebsiteID uint `gorm:"not null" json:"website_id"` // 关联的网站 ID
DNSID uint `gorm:"not null" json:"dns_id"` // 关联的 DNS ID
Type string `gorm:"not null" json:"type"` // 证书类型 (P256, P384, 2048, 4096)
Domains []string `gorm:"not null;serializer:json" json:"domains"`
AutoRenew bool `gorm:"not null" json:"auto_renew"` // 自动续签
CertURL string `gorm:"not null" json:"cert_url"` // 证书 URL (续签时使用)
Cert string `gorm:"not null" json:"cert"` // 证书内容
Key string `gorm:"not null" json:"key"` // 私钥内容
Website *Website `gorm:"foreignKey:WebsiteID" json:"website"`
User *CertUser `gorm:"foreignKey:UserID" json:"user"`

View File

@@ -1,22 +1,16 @@
package models
import (
"github.com/goravel/framework/support/carbon"
"github.com/goravel/framework/database/orm"
"github.com/TheTNB/panel/pkg/acme"
)
type CertDNS struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"not null" json:"name"` // 备注名称
Type string `gorm:"not null" json:"type"` // DNS 提供商 (dnspod, aliyun, cloudflare)
Data acme.DNSParam `gorm:"type:json;serializer:json" json:"dns_param"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Name string `gorm:"not null" json:"name"` // 备注名称
Type string `gorm:"not null" json:"type"` // DNS 提供商 (dnspod, aliyun, cloudflare)
Data acme.DNSParam `gorm:"not null;serializer:json" json:"dns_param"`
Certs []*Cert `gorm:"foreignKey:DNSID" json:"-"`
}
func (CertDNS) TableName() string {
return "cert_dns"
}

View File

@@ -1,19 +1,15 @@
package models
import (
"github.com/goravel/framework/support/carbon"
)
import "github.com/goravel/framework/database/orm"
type CertUser struct {
ID uint `gorm:"primaryKey" json:"id"`
Email string `gorm:"not null" json:"email"`
CA string `gorm:"not null" json:"ca"` // CA 提供商 (letsencrypt, zerossl, sslcom, google, buypass)
Kid *string `gorm:"default:null" json:"kid"`
HmacEncoded *string `gorm:"default:null" json:"hmac_encoded"`
PrivateKey string `gorm:"not null" json:"private_key"`
KeyType string `gorm:"not null" json:"key_type"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Email string `gorm:"not null" json:"email"`
CA string `gorm:"not null" json:"ca"` // CA 提供商 (letsencrypt, zerossl, sslcom, google, buypass)
Kid string `gorm:"not null" json:"kid"`
HmacEncoded string `gorm:"not null" json:"hmac_encoded"`
PrivateKey string `gorm:"not null" json:"private_key"`
KeyType string `gorm:"not null" json:"key_type"`
Certs []*Cert `gorm:"foreignKey:UserID" json:"-"`
}

View File

@@ -1,17 +1,13 @@
package models
import (
"github.com/goravel/framework/support/carbon"
)
import "github.com/goravel/framework/database/orm"
type Cron struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"not null;unique" json:"name"`
Status bool `gorm:"not null;default:false" json:"status"`
Type string `gorm:"not null" json:"type"`
Time string `gorm:"not null" json:"time"`
Shell string `gorm:"default:''" json:"shell"`
Log string `gorm:"default:''" json:"log"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Name string `gorm:"not null;unique" json:"name"`
Status bool `gorm:"not null" json:"status"`
Type string `gorm:"not null" json:"type"`
Time string `gorm:"not null" json:"time"`
Shell string `gorm:"not null" json:"shell"`
Log string `gorm:"not null" json:"log"`
}

View File

@@ -1,16 +1,14 @@
package models
import "github.com/goravel/framework/support/carbon"
import "github.com/goravel/framework/database/orm"
type Database struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"unique;not null" json:"name"`
Type string `gorm:"not null;index" json:"type"`
Host string `gorm:"not null" json:"host"`
Port int `gorm:"not null" json:"port"`
Username string `gorm:"not null" json:"username"`
Password string `gorm:"default:''" json:"password"`
Remark string `gorm:"default:''" json:"remark"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Name string `gorm:"not null;unique" json:"name"`
Type string `gorm:"not null" json:"type"`
Host string `gorm:"not null" json:"host"`
Port int `gorm:"not null" json:"port"`
Username string `gorm:"not null" json:"username"`
Password string `gorm:"not null" json:"password"`
Remark string `gorm:"not null" json:"remark"`
}

View File

@@ -1,14 +1,12 @@
package models
import (
"github.com/goravel/framework/support/carbon"
"github.com/goravel/framework/database/orm"
"github.com/TheTNB/panel/pkg/tools"
)
type Monitor struct {
ID uint `gorm:"primaryKey" json:"id"`
Info tools.MonitoringInfo `gorm:"type:json;serializer:json" json:"info"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Info tools.MonitoringInfo `gorm:"not null;serializer:json" json:"info"`
}

View File

@@ -1,13 +1,11 @@
package models
import "github.com/goravel/framework/support/carbon"
import "github.com/goravel/framework/database/orm"
type Plugin struct {
ID uint `gorm:"primaryKey" json:"id"`
Slug string `gorm:"unique;not null" json:"slug"`
Version string `gorm:"not null" json:"version"`
Show bool `gorm:"default:false;not null" json:"show"`
ShowOrder int `gorm:"default:0;not null" json:"show_order"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Slug string `gorm:"not null;unique" json:"slug"`
Version string `gorm:"not null" json:"version"`
Show bool `gorm:"not null" json:"show"`
ShowOrder int `gorm:"not null" json:"show_order"`
}

View File

@@ -1,6 +1,6 @@
package models
import "github.com/goravel/framework/support/carbon"
import "github.com/goravel/framework/database/orm"
const (
SettingKeyName = "name"
@@ -17,9 +17,7 @@ const (
)
type Setting struct {
ID uint `gorm:"primaryKey" json:"id"`
Key string `gorm:"unique;not null" json:"key"`
Value string `gorm:"default:''" json:"value"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Key string `gorm:"not null;unique" json:"key"`
Value string `gorm:"not null" json:"value"`
}

View File

@@ -1,8 +1,6 @@
package models
import (
"github.com/goravel/framework/support/carbon"
)
import "github.com/goravel/framework/database/orm"
const (
TaskStatusWaiting = "waiting"
@@ -12,11 +10,9 @@ const (
)
type Task struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"not null" json:"name"`
Status string `gorm:"not null;default:'waiting'" json:"status"`
Shell string `gorm:"default:''" json:"shell"`
Log string `gorm:"default:''" json:"log"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Name string `gorm:"not null;index" json:"name"`
Status string `gorm:"not null;default:'waiting'" json:"status"`
Shell string `gorm:"not null" json:"shell"`
Log string `gorm:"not null" json:"log"`
}

View File

@@ -1,12 +1,10 @@
package models
import "github.com/goravel/framework/support/carbon"
import "github.com/goravel/framework/database/orm"
type User struct {
ID uint `gorm:"primaryKey" json:"id"`
Username string `gorm:"unique;not null" json:"username"`
Password string `gorm:"not null" json:"password"`
Email string `gorm:"default:''" json:"email"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Username string `gorm:"not null;unique" json:"username"`
Password string `gorm:"not null" json:"password"`
Email string `gorm:"not null" json:"email"`
}

View File

@@ -1,19 +1,15 @@
package models
import (
"github.com/goravel/framework/support/carbon"
)
import "github.com/goravel/framework/database/orm"
type Website struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `json:"name"`
Status bool `gorm:"default:true" json:"status"`
Path string `json:"path"`
Php int `gorm:"default:0;not null;index" json:"php"`
Ssl bool `gorm:"default:false;not null;index" json:"ssl"`
Remark string `gorm:"default:''" json:"remark"`
CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
orm.Model
Name string `gorm:"not null;unique" json:"name"`
Status bool `gorm:"not null;default:true" json:"status"`
Path string `gorm:"not null" json:"path"`
Php int `gorm:"not null" json:"php"`
Ssl bool `gorm:"not null" json:"ssl"`
Remark string `gorm:"not null" json:"remark"`
Cert *Cert `gorm:"foreignKey:WebsiteID" json:"cert"`
}

View File

@@ -28,8 +28,8 @@ func (s *CertImpl) UserStore(request requests.UserStore) error {
var user models.CertUser
user.CA = request.CA
user.Email = request.Email
user.Kid = &request.Kid
user.HmacEncoded = &request.HmacEncoded
user.Kid = request.Kid
user.HmacEncoded = request.HmacEncoded
user.KeyType = request.KeyType
var err error
@@ -40,11 +40,11 @@ func (s *CertImpl) UserStore(request requests.UserStore) error {
case "buypass":
client, err = acme.NewRegisterAccount(context.Background(), user.Email, acme.CABuypass, nil, acme.KeyType(user.KeyType))
case "zerossl":
client, err = acme.NewRegisterAccount(context.Background(), user.Email, acme.CAZeroSSL, &acme.EAB{KeyID: *user.Kid, MACKey: *user.HmacEncoded}, acme.KeyType(user.KeyType))
client, err = acme.NewRegisterAccount(context.Background(), user.Email, acme.CAZeroSSL, &acme.EAB{KeyID: user.Kid, MACKey: user.HmacEncoded}, acme.KeyType(user.KeyType))
case "sslcom":
client, err = acme.NewRegisterAccount(context.Background(), user.Email, acme.CASSLcom, &acme.EAB{KeyID: *user.Kid, MACKey: *user.HmacEncoded}, acme.KeyType(user.KeyType))
client, err = acme.NewRegisterAccount(context.Background(), user.Email, acme.CASSLcom, &acme.EAB{KeyID: user.Kid, MACKey: user.HmacEncoded}, acme.KeyType(user.KeyType))
case "google":
client, err = acme.NewRegisterAccount(context.Background(), user.Email, acme.CAGoogle, &acme.EAB{KeyID: *user.Kid, MACKey: *user.HmacEncoded}, acme.KeyType(user.KeyType))
client, err = acme.NewRegisterAccount(context.Background(), user.Email, acme.CAGoogle, &acme.EAB{KeyID: user.Kid, MACKey: user.HmacEncoded}, acme.KeyType(user.KeyType))
default:
return errors.New("CA 提供商不支持")
}
@@ -72,8 +72,8 @@ func (s *CertImpl) UserUpdate(request requests.UserUpdate) error {
user.CA = request.CA
user.Email = request.Email
user.Kid = &request.Kid
user.HmacEncoded = &request.HmacEncoded
user.Kid = request.Kid
user.HmacEncoded = request.HmacEncoded
user.KeyType = request.KeyType
var client *acme.Client
@@ -83,11 +83,11 @@ func (s *CertImpl) UserUpdate(request requests.UserUpdate) error {
case "buypass":
client, err = acme.NewRegisterAccount(context.Background(), user.Email, acme.CABuypass, nil, acme.KeyType(user.KeyType))
case "zerossl":
client, err = acme.NewRegisterAccount(context.Background(), user.Email, acme.CAZeroSSL, &acme.EAB{KeyID: *user.Kid, MACKey: *user.HmacEncoded}, acme.KeyType(user.KeyType))
client, err = acme.NewRegisterAccount(context.Background(), user.Email, acme.CAZeroSSL, &acme.EAB{KeyID: user.Kid, MACKey: user.HmacEncoded}, acme.KeyType(user.KeyType))
case "sslcom":
client, err = acme.NewRegisterAccount(context.Background(), user.Email, acme.CASSLcom, &acme.EAB{KeyID: *user.Kid, MACKey: *user.HmacEncoded}, acme.KeyType(user.KeyType))
client, err = acme.NewRegisterAccount(context.Background(), user.Email, acme.CASSLcom, &acme.EAB{KeyID: user.Kid, MACKey: user.HmacEncoded}, acme.KeyType(user.KeyType))
case "google":
client, err = acme.NewRegisterAccount(context.Background(), user.Email, acme.CAGoogle, &acme.EAB{KeyID: *user.Kid, MACKey: *user.HmacEncoded}, acme.KeyType(user.KeyType))
client, err = acme.NewRegisterAccount(context.Background(), user.Email, acme.CAGoogle, &acme.EAB{KeyID: user.Kid, MACKey: user.HmacEncoded}, acme.KeyType(user.KeyType))
default:
return errors.New("CA 提供商不支持")
}
@@ -262,7 +262,7 @@ func (s *CertImpl) ObtainAuto(ID uint) (acme.Certificate, error) {
return acme.Certificate{}, err
}
cert.CertURL = &ssl.URL
cert.CertURL = ssl.URL
cert.Cert = string(ssl.ChainPEM)
cert.Key = string(ssl.PrivateKey)
err = facades.Orm().Query().Save(&cert)
@@ -302,7 +302,7 @@ func (s *CertImpl) ObtainManual(ID uint) (acme.Certificate, error) {
return acme.Certificate{}, err
}
cert.CertURL = &ssl.URL
cert.CertURL = ssl.URL
cert.Cert = string(ssl.ChainPEM)
cert.Key = string(ssl.PrivateKey)
err = facades.Orm().Query().Save(&cert)
@@ -363,7 +363,7 @@ func (s *CertImpl) Renew(ID uint) (acme.Certificate, error) {
return acme.Certificate{}, err
}
if cert.CertURL == nil {
if cert.CertURL == "" {
return acme.Certificate{}, errors.New("该证书没有签发成功,无法续签")
}
@@ -382,12 +382,12 @@ func (s *CertImpl) Renew(ID uint) (acme.Certificate, error) {
}
}
ssl, err := client.RenewSSL(context.Background(), *cert.CertURL, cert.Domains, acme.KeyType(cert.Type))
ssl, err := client.RenewSSL(context.Background(), cert.CertURL, cert.Domains, acme.KeyType(cert.Type))
if err != nil {
return acme.Certificate{}, err
}
cert.CertURL = &ssl.URL
cert.CertURL = ssl.URL
cert.Cert = string(ssl.ChainPEM)
cert.Key = string(ssl.PrivateKey)
err = facades.Orm().Query().Save(&cert)
@@ -451,13 +451,13 @@ func (s *CertImpl) getClient(cert models.Cert) (*acme.Client, error) {
ca = acme.CABuypass
case "zerossl":
ca = acme.CAZeroSSL
eab = &acme.EAB{KeyID: *cert.User.Kid, MACKey: *cert.User.HmacEncoded}
eab = &acme.EAB{KeyID: cert.User.Kid, MACKey: cert.User.HmacEncoded}
case "sslcom":
ca = acme.CASSLcom
eab = &acme.EAB{KeyID: *cert.User.Kid, MACKey: *cert.User.HmacEncoded}
eab = &acme.EAB{KeyID: cert.User.Kid, MACKey: cert.User.HmacEncoded}
case "google":
ca = acme.CAGoogle
eab = &acme.EAB{KeyID: *cert.User.Kid, MACKey: *cert.User.HmacEncoded}
eab = &acme.EAB{KeyID: cert.User.Kid, MACKey: cert.User.HmacEncoded}
}
return acme.NewPrivateKeyAccount(cert.User.Email, cert.User.PrivateKey, ca, eab)