mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 07:57:21 +08:00
feat: 优化自动签发证书
This commit is contained in:
2
go.mod
2
go.mod
@@ -130,4 +130,4 @@ require (
|
||||
modernc.org/sqlite v1.32.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/mholt/acmez/v2 => github.com/TheTNB/acmez/v2 v2.0.0-20241012163130-5833d84639e0
|
||||
replace github.com/mholt/acmez/v2 => github.com/TheTNB/acmez/v2 v2.0.0-20241025203320-cc718c4c870b
|
||||
|
||||
4
go.sum
4
go.sum
@@ -23,8 +23,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU=
|
||||
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
|
||||
github.com/TheTNB/acmez/v2 v2.0.0-20241012163130-5833d84639e0 h1:o66ZhpjXVs7oi3VyiZvlpp9StFFe4KTeklzB/T4s59Q=
|
||||
github.com/TheTNB/acmez/v2 v2.0.0-20241012163130-5833d84639e0/go.mod h1:pQ1ysaDeGrIMvJ9dfJMk5kJNkn7L2sb3UhyrX6Q91cw=
|
||||
github.com/TheTNB/acmez/v2 v2.0.0-20241025203320-cc718c4c870b h1:1iVxCglpEJ/kq48YcujkWq8SeOacMuMmuekMmGyOSPA=
|
||||
github.com/TheTNB/acmez/v2 v2.0.0-20241025203320-cc718c4c870b/go.mod h1:pQ1ysaDeGrIMvJ9dfJMk5kJNkn7L2sb3UhyrX6Q91cw=
|
||||
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
|
||||
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/beevik/ntp v1.4.3 h1:PlbTvE5NNy4QHmA4Mg57n7mcFTmr1W1j3gcK7L1lqho=
|
||||
|
||||
@@ -29,6 +29,7 @@ type Cert struct {
|
||||
type CertRepo interface {
|
||||
List(page, limit uint) ([]*Cert, int64, error)
|
||||
Get(id uint) (*Cert, error)
|
||||
GetByWebsite(WebsiteID uint) (*Cert, error)
|
||||
Create(req *request.CertCreate) (*Cert, error)
|
||||
Update(req *request.CertUpdate) error
|
||||
Delete(id uint) error
|
||||
|
||||
@@ -37,6 +37,12 @@ func (r *certRepo) Get(id uint) (*biz.Cert, error) {
|
||||
return cert, err
|
||||
}
|
||||
|
||||
func (r *certRepo) GetByWebsite(WebsiteID uint) (*biz.Cert, error) {
|
||||
cert := new(biz.Cert)
|
||||
err := app.Orm.Model(&biz.Cert{}).Preload("Website").Preload("Account").Preload("DNS").Where("website_id = ?", WebsiteID).First(cert).Error
|
||||
return cert, err
|
||||
}
|
||||
|
||||
func (r *certRepo) Create(req *request.CertCreate) (*biz.Cert, error) {
|
||||
cert := &biz.Cert{
|
||||
AccountID: req.AccountID,
|
||||
|
||||
@@ -34,8 +34,13 @@ func (r certAccountRepo) GetDefault(userID uint) (*biz.CertAccount, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
account := new(biz.CertAccount)
|
||||
if err = app.Orm.Model(&biz.CertAccount{}).Where("ca = ?", "googlecn").Where("email = ?", user.Email).First(account).Error; err == nil {
|
||||
return account, nil
|
||||
}
|
||||
|
||||
req := &request.CertAccountCreate{
|
||||
CA: acme.CAGoogleCN,
|
||||
CA: "googlecn",
|
||||
Email: user.Email,
|
||||
KeyType: string(acme.KeyEC256),
|
||||
}
|
||||
|
||||
@@ -695,15 +695,18 @@ func (r *websiteRepo) ObtainCert(ctx context.Context, id uint) error {
|
||||
}
|
||||
|
||||
cRepo := NewCertRepo()
|
||||
newCert, err := cRepo.Create(&request.CertCreate{
|
||||
Type: string(acme.KeyEC256),
|
||||
Domains: website.Domains,
|
||||
AutoRenew: true,
|
||||
AccountID: account.ID,
|
||||
WebsiteID: website.ID,
|
||||
})
|
||||
newCert, err := cRepo.GetByWebsite(website.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
newCert, err = cRepo.Create(&request.CertCreate{
|
||||
Type: string(acme.KeyEC256),
|
||||
Domains: website.Domains,
|
||||
AutoRenew: true,
|
||||
AccountID: account.ID,
|
||||
WebsiteID: website.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
_, err = cRepo.ObtainAuto(newCert.ID)
|
||||
|
||||
@@ -22,7 +22,7 @@ type FileCreate struct {
|
||||
|
||||
type FileSave struct {
|
||||
Path string `form:"path" json:"path" validate:"required"`
|
||||
Content string `form:"content" json:"content" validate:"required"`
|
||||
Content string `form:"content" json:"content"`
|
||||
}
|
||||
|
||||
type FileMove struct {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import Editor from '@guolao/vue-monaco-editor'
|
||||
import type { MessageReactive } from 'naive-ui'
|
||||
import { NButton, NDataTable, NFlex, NPopconfirm, NSpace, NSwitch, NTable, NTag } from 'naive-ui'
|
||||
|
||||
import cert from '@/api/panel/cert'
|
||||
@@ -15,7 +16,7 @@ const props = defineProps({
|
||||
|
||||
const { algorithms, websites, accounts, dns, caProviders } = toRefs(props)
|
||||
|
||||
let messageReactive: any
|
||||
let messageReactive: MessageReactive | null = null
|
||||
|
||||
const updateCertModel = ref<any>({
|
||||
domains: [],
|
||||
|
||||
@@ -4,12 +4,15 @@ defineOptions({
|
||||
})
|
||||
|
||||
import Editor from '@guolao/vue-monaco-editor'
|
||||
import type { MessageReactive } from 'naive-ui'
|
||||
import { NButton } from 'naive-ui'
|
||||
|
||||
import dashboard from '@/api/panel/dashboard'
|
||||
import website from '@/api/panel/website'
|
||||
import type { WebsiteListen, WebsiteSetting } from '@/views/website/types'
|
||||
|
||||
let messageReactive: MessageReactive | null = null
|
||||
|
||||
const current = ref('listen')
|
||||
const route = useRoute()
|
||||
const { id } = route.params
|
||||
@@ -97,10 +100,18 @@ const handleReset = async () => {
|
||||
}
|
||||
|
||||
const handleObtainCert = async () => {
|
||||
await website.obtainCert(Number(id)).then(() => {
|
||||
getWebsiteSetting()
|
||||
window.$message.success('成功,请开启 HTTPS 并保存')
|
||||
messageReactive = window.$message.loading('请稍后...', {
|
||||
duration: 0
|
||||
})
|
||||
await website
|
||||
.obtainCert(Number(id))
|
||||
.then(() => {
|
||||
getWebsiteSetting()
|
||||
window.$message.success('签发成功')
|
||||
})
|
||||
.finally(() => {
|
||||
messageReactive?.destroy()
|
||||
})
|
||||
}
|
||||
|
||||
const clearLog = async () => {
|
||||
|
||||
Reference in New Issue
Block a user