mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +02:00
parent
11e460765a
commit
b3486a42a5
41 changed files with 2429 additions and 1649 deletions
|
@ -4,6 +4,8 @@ import (
|
|||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cert"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cosy"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/internal/notification"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -86,6 +88,7 @@ type certJson struct {
|
|||
ChallengeMethod string `json:"challenge_method"`
|
||||
DnsCredentialID int `json:"dns_credential_id"`
|
||||
ACMEUserID int `json:"acme_user_id"`
|
||||
SyncNodeIds []int `json:"sync_node_ids"`
|
||||
}
|
||||
|
||||
func AddCert(c *gin.Context) {
|
||||
|
@ -103,6 +106,7 @@ func AddCert(c *gin.Context) {
|
|||
ChallengeMethod: json.ChallengeMethod,
|
||||
DnsCredentialID: json.DnsCredentialID,
|
||||
ACMEUserID: json.ACMEUserID,
|
||||
SyncNodeIds: json.SyncNodeIds,
|
||||
}
|
||||
|
||||
err := certModel.Insert()
|
||||
|
@ -126,6 +130,12 @@ func AddCert(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
err = cert.SyncToRemoteServer(certModel)
|
||||
if err != nil {
|
||||
notification.Error("Sync Certificate Error", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, Transformer(certModel))
|
||||
}
|
||||
|
||||
|
@ -154,6 +164,7 @@ func ModifyCert(c *gin.Context) {
|
|||
KeyType: json.KeyType,
|
||||
DnsCredentialID: json.DnsCredentialID,
|
||||
ACMEUserID: json.ACMEUserID,
|
||||
SyncNodeIds: json.SyncNodeIds,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
@ -175,9 +186,58 @@ func ModifyCert(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
err = cert.SyncToRemoteServer(certModel)
|
||||
if err != nil {
|
||||
notification.Error("Sync Certificate Error", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
GetCert(c)
|
||||
}
|
||||
|
||||
func RemoveCert(c *gin.Context) {
|
||||
cosy.Core[model.Cert](c).Destroy()
|
||||
}
|
||||
|
||||
func SyncCertificate(c *gin.Context) {
|
||||
var json cert.SyncCertificatePayload
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
certModel := &model.Cert{
|
||||
Name: json.Name,
|
||||
SSLCertificatePath: json.SSLCertificatePath,
|
||||
SSLCertificateKeyPath: json.SSLCertificateKeyPath,
|
||||
KeyType: json.KeyType,
|
||||
AutoCert: model.AutoCertSync,
|
||||
}
|
||||
|
||||
db := model.UseDB()
|
||||
|
||||
err := db.Where(certModel).FirstOrCreate(certModel).Error
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
content := &cert.Content{
|
||||
SSLCertificatePath: json.SSLCertificatePath,
|
||||
SSLCertificateKeyPath: json.SSLCertificateKeyPath,
|
||||
SSLCertificate: json.SSLCertificate,
|
||||
SSLCertificateKey: json.SSLCertificateKey,
|
||||
}
|
||||
|
||||
err = content.WriteFile()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
nginx.Reload()
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ func InitCertificateRouter(r *gin.RouterGroup) {
|
|||
r.POST("cert", AddCert)
|
||||
r.POST("cert/:id", ModifyCert)
|
||||
r.DELETE("cert/:id", RemoveCert)
|
||||
r.PUT("cert_sync", SyncCertificate)
|
||||
r.GET("certificate/dns_providers", GetDNSProvidersList)
|
||||
r.GET("certificate/dns_provider/:code", GetDNSProvider)
|
||||
}
|
||||
|
|
|
@ -30,8 +30,7 @@ func GetList(c *gin.Context) {
|
|||
}
|
||||
|
||||
func Destroy(c *gin.Context) {
|
||||
cosy.Core[model.Notification](c).
|
||||
PermanentlyDelete()
|
||||
cosy.Core[model.Notification](c).Destroy()
|
||||
}
|
||||
|
||||
func DestroyAll(c *gin.Context) {
|
||||
|
|
|
@ -22,14 +22,12 @@ func GetDomains(c *gin.Context) {
|
|||
sort := c.DefaultQuery("sort", "desc")
|
||||
|
||||
configFiles, err := os.ReadDir(nginx.GetConfPath("sites-available"))
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
enabledConfig, err := os.ReadDir(nginx.GetConfPath("sites-enabled"))
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue