fix: unable to create a certificate from a second environment #273

This commit is contained in:
0xJacky 2024-02-06 16:20:46 +08:00
parent abe43c5c4d
commit 2526d71c0e
No known key found for this signature in database
GPG key ID: B6E4A6E4A561BAF0
5 changed files with 198 additions and 87 deletions

View file

@ -11,7 +11,6 @@ func InitDNSCredentialRouter(r *gin.RouterGroup) {
}
func InitCertificateRouter(r *gin.RouterGroup) {
r.GET("domain/:name/cert", IssueCert)
r.GET("certs", GetCertList)
r.GET("cert/:id", GetCert)
r.POST("cert", AddCert)
@ -20,3 +19,7 @@ func InitCertificateRouter(r *gin.RouterGroup) {
r.GET("certificate/dns_providers", GetDNSProvidersList)
r.GET("certificate/dns_provider/:code", GetDNSProvider)
}
func InitCertificateWebSocketRouter(r *gin.RouterGroup) {
r.GET("domain/:name/cert", IssueCert)
}

View file

@ -1,50 +1,50 @@
package config
import (
"github.com/0xJacky/Nginx-UI/api"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/gin-gonic/gin"
"net/http"
"os"
"github.com/0xJacky/Nginx-UI/api"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/gin-gonic/gin"
"net/http"
"os"
)
type EditConfigJson struct {
Content string `json:"content" binding:"required"`
Content string `json:"content" binding:"required"`
}
func EditConfig(c *gin.Context) {
name := c.Param("name")
var request EditConfigJson
err := c.BindJSON(&request)
if err != nil {
api.ErrHandler(c, err)
return
}
path := nginx.GetConfPath("/", name)
content := request.Content
name := c.Param("name")
var request EditConfigJson
err := c.BindJSON(&request)
if err != nil {
api.ErrHandler(c, err)
return
}
path := nginx.GetConfPath("/", name)
content := request.Content
origContent, err := os.ReadFile(path)
if err != nil {
api.ErrHandler(c, err)
return
}
origContent, err := os.ReadFile(path)
if err != nil {
api.ErrHandler(c, err)
return
}
if content != "" && content != string(origContent) {
err = os.WriteFile(path, []byte(content), 0644)
if err != nil {
api.ErrHandler(c, err)
return
}
}
if content != "" && content != string(origContent) {
err = os.WriteFile(path, []byte(content), 0644)
if err != nil {
api.ErrHandler(c, err)
return
}
}
output := nginx.Reload()
output := nginx.Reload()
if nginx.GetLogLevel(output) >= nginx.Warn {
c.JSON(http.StatusInternalServerError, gin.H{
"message": output,
})
return
}
if nginx.GetLogLevel(output) >= nginx.Warn {
c.JSON(http.StatusInternalServerError, gin.H{
"message": output,
})
return
}
GetConfig(c)
GetConfig(c)
}