@@ -3,11 +3,14 @@ package settings
33import (
44 "fmt"
55 "net/http"
6+ "time"
67
78 "github.com/0xJacky/Nginx-UI/internal/cron"
89 "github.com/0xJacky/Nginx-UI/internal/nginx"
10+ "github.com/0xJacky/Nginx-UI/internal/system"
911 "github.com/0xJacky/Nginx-UI/settings"
1012 "github.com/gin-gonic/gin"
13+ "github.com/jpillora/overseer"
1114 "github.com/uozi-tech/cosy"
1215 cSettings "github.com/uozi-tech/cosy/settings"
1316)
@@ -61,6 +64,8 @@ func GetSettings(c *gin.Context) {
6164
6265func SaveSettings (c * gin.Context ) {
6366 var json struct {
67+ App cSettings.App `json:"app"`
68+ Server cSettings.Server `json:"server"`
6469 Auth settings.Auth `json:"auth"`
6570 Cert settings.Cert `json:"cert"`
6671 Http settings.HTTP `json:"http"`
@@ -78,6 +83,22 @@ func SaveSettings(c *gin.Context) {
7883 go cron .RestartLogrotate ()
7984 }
8085
86+ // Validate SSL certificates if HTTPS is enabled
87+ needRestart := false
88+ if json .Server .EnableHTTPS != cSettings .ServerSettings .EnableHTTPS {
89+ needRestart = true
90+ }
91+
92+ if json .Server .EnableHTTPS {
93+ err := system .ValidateSSLCertificates (json .Server .SSLCert , json .Server .SSLKey )
94+ if err != nil {
95+ cosy .ErrHandler (c , err )
96+ return
97+ }
98+ }
99+
100+ cSettings .ProtectedFill (cSettings .AppSettings , & json .App )
101+ cSettings .ProtectedFill (cSettings .ServerSettings , & json .Server )
81102 cSettings .ProtectedFill (settings .AuthSettings , & json .Auth )
82103 cSettings .ProtectedFill (settings .CertSettings , & json .Cert )
83104 cSettings .ProtectedFill (settings .HTTPSettings , & json .Http )
@@ -91,5 +112,12 @@ func SaveSettings(c *gin.Context) {
91112 return
92113 }
93114
115+ if needRestart {
116+ go func () {
117+ time .Sleep (2 * time .Second )
118+ overseer .Restart ()
119+ }()
120+ }
121+
94122 GetSettings (c )
95123}
0 commit comments