mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
feat: SSL management support different types of certificates of a same doamin name #309
This commit is contained in:
parent
464e84a64f
commit
3e90b838fd
11 changed files with 54 additions and 24 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-acme/lego/v4/certcrypto"
|
||||
"github.com/gorilla/websocket"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
@ -18,10 +19,11 @@ const (
|
|||
)
|
||||
|
||||
type IssueCertResponse struct {
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message"`
|
||||
SSLCertificate string `json:"ssl_certificate,omitempty"`
|
||||
SSLCertificateKey string `json:"ssl_certificate_key,omitempty"`
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message"`
|
||||
SSLCertificate string `json:"ssl_certificate,omitempty"`
|
||||
SSLCertificateKey string `json:"ssl_certificate_key,omitempty"`
|
||||
KeyType certcrypto.KeyType `json:"key_type"`
|
||||
}
|
||||
|
||||
func handleIssueCertLogChan(conn *websocket.Conn, log *cert.Logger, logChan chan string) {
|
||||
|
@ -75,8 +77,7 @@ func IssueCert(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
certModel, err := model.FirstOrCreateCert(c.Param("name"))
|
||||
|
||||
certModel, err := model.FirstOrCreateCert(c.Param("name"), payload.GetKeyType())
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
|
@ -113,7 +114,7 @@ func IssueCert(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
certDirName := strings.Join(payload.ServerName, "_")
|
||||
certDirName := strings.Join(payload.ServerName, "_") + "_" + string(payload.GetKeyType())
|
||||
sslCertificatePath := nginx.GetConfPath("ssl", certDirName, "fullchain.cer")
|
||||
sslCertificateKeyPath := nginx.GetConfPath("ssl", certDirName, "private.key")
|
||||
|
||||
|
@ -144,6 +145,7 @@ func IssueCert(c *gin.Context) {
|
|||
Message: "Issued certificate successfully",
|
||||
SSLCertificate: sslCertificatePath,
|
||||
SSLCertificateKey: sslCertificateKeyPath,
|
||||
KeyType: payload.GetKeyType(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -2,8 +2,10 @@ package sites
|
|||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-acme/lego/v4/certcrypto"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
@ -11,16 +13,17 @@ func AddDomainToAutoCert(c *gin.Context) {
|
|||
name := c.Param("name")
|
||||
|
||||
var json struct {
|
||||
DnsCredentialID int `json:"dns_credential_id"`
|
||||
ChallengeMethod string `json:"challenge_method"`
|
||||
Domains []string `json:"domains"`
|
||||
DnsCredentialID int `json:"dns_credential_id"`
|
||||
ChallengeMethod string `json:"challenge_method"`
|
||||
Domains []string `json:"domains"`
|
||||
KeyType certcrypto.KeyType `json:"key_type"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
certModel, err := model.FirstOrCreateCert(name)
|
||||
certModel, err := model.FirstOrCreateCert(name, helper.GetKeyType(json.KeyType))
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue