mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
fix(cert): maybe panic when add or modify #1034
This commit is contained in:
parent
adf6f80061
commit
c241122fde
1 changed files with 22 additions and 16 deletions
|
@ -103,7 +103,7 @@ func AddCert(c *gin.Context) {
|
||||||
"revoke_old": "omitempty",
|
"revoke_old": "omitempty",
|
||||||
}).
|
}).
|
||||||
BeforeExecuteHook(func(ctx *cosy.Ctx[model.Cert]) {
|
BeforeExecuteHook(func(ctx *cosy.Ctx[model.Cert]) {
|
||||||
sslCertificate := ctx.Payload["ssl_certificate"].(string)
|
sslCertificate := cast.ToString(ctx.Payload["ssl_certificate"])
|
||||||
// Detect and set certificate type
|
// Detect and set certificate type
|
||||||
if sslCertificate != "" {
|
if sslCertificate != "" {
|
||||||
keyType, err := cert.GetKeyType(sslCertificate)
|
keyType, err := cert.GetKeyType(sslCertificate)
|
||||||
|
@ -125,18 +125,22 @@ func AddCert(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}).
|
}).
|
||||||
ExecutedHook(func(ctx *cosy.Ctx[model.Cert]) {
|
ExecutedHook(func(ctx *cosy.Ctx[model.Cert]) {
|
||||||
content := &cert.Content{
|
sslCertificate := cast.ToString(ctx.Payload["ssl_certificate"])
|
||||||
SSLCertificatePath: ctx.Model.SSLCertificatePath,
|
sslCertificateKey := cast.ToString(ctx.Payload["ssl_certificate_key"])
|
||||||
SSLCertificateKeyPath: ctx.Model.SSLCertificateKeyPath,
|
if sslCertificate != "" && sslCertificateKey != "" {
|
||||||
SSLCertificate: ctx.Payload["ssl_certificate"].(string),
|
content := &cert.Content{
|
||||||
SSLCertificateKey: ctx.Payload["ssl_certificate_key"].(string),
|
SSLCertificatePath: ctx.Model.SSLCertificatePath,
|
||||||
|
SSLCertificateKeyPath: ctx.Model.SSLCertificateKeyPath,
|
||||||
|
SSLCertificate: sslCertificate,
|
||||||
|
SSLCertificateKey: sslCertificateKey,
|
||||||
|
}
|
||||||
|
err := content.WriteFile()
|
||||||
|
if err != nil {
|
||||||
|
ctx.AbortWithError(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
err := content.WriteFile()
|
err := cert.SyncToRemoteServer(&ctx.Model)
|
||||||
if err != nil {
|
|
||||||
ctx.AbortWithError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = cert.SyncToRemoteServer(&ctx.Model)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
notification.Error("Sync Certificate Error", err.Error(), nil)
|
notification.Error("Sync Certificate Error", err.Error(), nil)
|
||||||
return
|
return
|
||||||
|
@ -165,7 +169,7 @@ func ModifyCert(c *gin.Context) {
|
||||||
"revoke_old": "omitempty",
|
"revoke_old": "omitempty",
|
||||||
}).
|
}).
|
||||||
BeforeExecuteHook(func(ctx *cosy.Ctx[model.Cert]) {
|
BeforeExecuteHook(func(ctx *cosy.Ctx[model.Cert]) {
|
||||||
sslCertificate := ctx.Payload["ssl_certificate"].(string)
|
sslCertificate := cast.ToString(ctx.Payload["ssl_certificate"])
|
||||||
// Detect and set certificate type
|
// Detect and set certificate type
|
||||||
if sslCertificate != "" {
|
if sslCertificate != "" {
|
||||||
keyType, err := cert.GetKeyType(sslCertificate)
|
keyType, err := cert.GetKeyType(sslCertificate)
|
||||||
|
@ -187,11 +191,14 @@ func ModifyCert(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}).
|
}).
|
||||||
ExecutedHook(func(ctx *cosy.Ctx[model.Cert]) {
|
ExecutedHook(func(ctx *cosy.Ctx[model.Cert]) {
|
||||||
|
sslCertificate := cast.ToString(ctx.Payload["ssl_certificate"])
|
||||||
|
sslCertificateKey := cast.ToString(ctx.Payload["ssl_certificate_key"])
|
||||||
|
|
||||||
content := &cert.Content{
|
content := &cert.Content{
|
||||||
SSLCertificatePath: ctx.Model.SSLCertificatePath,
|
SSLCertificatePath: ctx.Model.SSLCertificatePath,
|
||||||
SSLCertificateKeyPath: ctx.Model.SSLCertificateKeyPath,
|
SSLCertificateKeyPath: ctx.Model.SSLCertificateKeyPath,
|
||||||
SSLCertificate: ctx.Payload["ssl_certificate"].(string),
|
SSLCertificate: sslCertificate,
|
||||||
SSLCertificateKey: ctx.Payload["ssl_certificate_key"].(string),
|
SSLCertificateKey: sslCertificateKey,
|
||||||
}
|
}
|
||||||
err := content.WriteFile()
|
err := content.WriteFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -203,7 +210,6 @@ func ModifyCert(c *gin.Context) {
|
||||||
notification.Error("Sync Certificate Error", err.Error(), nil)
|
notification.Error("Sync Certificate Error", err.Error(), nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}).
|
}).
|
||||||
SetNextHandler(GetCert).
|
SetNextHandler(GetCert).
|
||||||
Modify()
|
Modify()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue