diff --git a/agent/app/service/app.go b/agent/app/service/app.go index aa7fb2435..5876e3470 100644 --- a/agent/app/service/app.go +++ b/agent/app/service/app.go @@ -488,7 +488,9 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App if err = runScript(t, appInstall, "init"); err != nil { return err } - upApp(t, appInstall, req.PullImage) + if err = upApp(t, appInstall, req.PullImage); err != nil { + return err + } updateToolApp(appInstall) return nil } diff --git a/agent/app/service/app_utils.go b/agent/app/service/app_utils.go index 416f3caea..c1324640b 100644 --- a/agent/app/service/app_utils.go +++ b/agent/app/service/app_utils.go @@ -1022,7 +1022,7 @@ func checkContainerNameIsExist(containerName, appDir string) (bool, error) { return false, nil } -func upApp(task *task.Task, appInstall *model.AppInstall, pullImages bool) { +func upApp(task *task.Task, appInstall *model.AppInstall, pullImages bool) error { upProject := func(appInstall *model.AppInstall) (err error) { var ( out string @@ -1079,14 +1079,6 @@ func upApp(task *task.Task, appInstall *model.AppInstall, pullImages bool) { task.LogSuccess(logStr) return } - if err := upProject(appInstall); err != nil { - if appInstall.Message == "" { - appInstall.Message = err.Error() - } - appInstall.Status = constant.UpErr - } else { - appInstall.Status = constant.Running - } exist, _ := appInstallRepo.GetFirst(commonRepo.WithByID(appInstall.ID)) if exist.ID > 0 { containerNames, err := getContainerNames(*appInstall) @@ -1097,6 +1089,16 @@ func upApp(task *task.Task, appInstall *model.AppInstall, pullImages bool) { _ = appInstallRepo.Save(context.Background(), appInstall) } } + if err := upProject(appInstall); err != nil { + if appInstall.Message == "" { + appInstall.Message = err.Error() + } + appInstall.Status = constant.UpErr + return err + } else { + appInstall.Status = constant.Running + return nil + } } func rebuildApp(appInstall model.AppInstall) error { diff --git a/agent/app/service/website_ssl.go b/agent/app/service/website_ssl.go index 171635c33..b9cf92188 100644 --- a/agent/app/service/website_ssl.go +++ b/agent/app/service/website_ssl.go @@ -6,6 +6,7 @@ import ( "crypto/x509" "encoding/pem" "fmt" + http2 "github.com/1Panel-dev/1Panel/agent/utils/http" "log" "os" "path" @@ -204,6 +205,10 @@ func reloadSystemSSL(websiteSSL *model.WebsiteSSL, logger *log.Logger) { logger.Printf("Failed to update the SSL certificate for 1Panel System domain [%s] , err:%s", websiteSSL.PrimaryDomain, err.Error()) return } + if err := http2.PostLocalCore("/core/settings/ssl/reload"); err != nil { + logger.Printf("Failed to update the SSL certificate for 1Panel System domain [%s] , err:%s", websiteSSL.PrimaryDomain, err.Error()) + return + } printSSLLog(logger, "UpdateSystemSSLSuccess", nil, logger == nil) } } diff --git a/agent/i18n/i18n.go b/agent/i18n/i18n.go index 22bc0990a..3f718d0db 100644 --- a/agent/i18n/i18n.go +++ b/agent/i18n/i18n.go @@ -125,4 +125,5 @@ func Init() { _, _ = bundle.LoadMessageFileFS(fs, "lang/zh.yaml") _, _ = bundle.LoadMessageFileFS(fs, "lang/en.yaml") _, _ = bundle.LoadMessageFileFS(fs, "lang/zh-Hant.yaml") + global.I18n = i18n.NewLocalizer(bundle, "en") } diff --git a/agent/init/business/business.go b/agent/init/business/business.go index fb39efbff..663036fc4 100644 --- a/agent/init/business/business.go +++ b/agent/init/business/business.go @@ -7,8 +7,7 @@ import ( ) func Init() { - //TODO 国际化处理 - //go syncApp() + go syncApp() go syncInstalledApp() go syncRuntime() go syncSSL() diff --git a/agent/utils/http/core.go b/agent/utils/http/core.go new file mode 100644 index 000000000..87eb6350f --- /dev/null +++ b/agent/utils/http/core.go @@ -0,0 +1,38 @@ +package http + +import ( + "bytes" + "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" + "net/http" +) + +func PostLocalCore(url string) error { + settingRepo := repo.NewISettingRepo() + port, err := settingRepo.GetValueByKey("ServerPort") + if err != nil { + return err + } + sslStatus, err := settingRepo.GetValueByKey("SSL") + if err != nil { + return err + } + var prefix string + if sslStatus == "Disable" { + prefix = "http://" + } else { + prefix = "https://" + } + reloadURL := fmt.Sprintf("%s://127.0.0.1:%s/api/v2%s", prefix, port, url) + req, err := http.NewRequest("POST", reloadURL, bytes.NewBuffer([]byte{})) + if err != nil { + return err + } + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() + return nil +} diff --git a/core/app/api/v2/setting.go b/core/app/api/v2/setting.go index 8676d12b0..163def23a 100644 --- a/core/app/api/v2/setting.go +++ b/core/app/api/v2/setting.go @@ -369,3 +369,16 @@ func (b *BaseApi) MFABind(c *gin.Context) { helper.SuccessWithData(c, nil) } + +func (b *BaseApi) ReloadSSL(c *gin.Context) { + clientIP := c.ClientIP() + if clientIP != "127.0.0.1" { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, errors.New("only localhost can reload ssl")) + return + } + if err := settingService.UpdateSystemSSL(); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithOutData(c) +} diff --git a/core/app/service/setting.go b/core/app/service/setting.go index 14a2e5da9..ca3e62e71 100644 --- a/core/app/service/setting.go +++ b/core/app/service/setting.go @@ -40,6 +40,8 @@ type ISettingService interface { GetTerminalInfo() (*dto.TerminalInfo, error) UpdateTerminal(req dto.TerminalInfo) error + + UpdateSystemSSL() error } func NewISettingService() ISettingService { @@ -198,15 +200,6 @@ func (u *SettingService) UpdateSSL(c *gin.Context, req dto.SSLUpdate) error { } _ = os.Remove(path.Join(secretDir, "server.crt")) _ = os.Remove(path.Join(secretDir, "server.key")) - sID, _ := c.Cookie(constant.SessionName) - c.SetCookie(constant.SessionName, sID, 0, "", "", false, true) - - go func() { - _, err := cmd.Exec("systemctl restart 1panel.service") - if err != nil { - global.LOG.Errorf("restart system failed, err: %v", err) - } - }() return nil } if _, err := os.Stat(secretDir); err != nil && os.IsNotExist(err) { @@ -257,17 +250,7 @@ func (u *SettingService) UpdateSSL(c *gin.Context, req dto.SSLUpdate) error { if err := settingRepo.Update("SSL", req.SSL); err != nil { return err } - - sID, _ := c.Cookie(constant.SessionName) - c.SetCookie(constant.SessionName, sID, 0, "", "", true, true) - go func() { - time.Sleep(1 * time.Second) - _, err := cmd.Exec("systemctl restart 1panel.service") - if err != nil { - global.LOG.Errorf("restart system failed, err: %v", err) - } - }() - return nil + return u.UpdateSystemSSL() } func (u *SettingService) LoadFromCert() (*dto.SSLInfo, error) { @@ -394,6 +377,25 @@ func (u *SettingService) UpdatePassword(c *gin.Context, old, new string) error { return nil } +func (u *SettingService) UpdateSystemSSL() error { + certPath := path.Join(global.CONF.System.BaseDir, "1panel/secret/server.crt") + keyPath := path.Join(global.CONF.System.BaseDir, "1panel/secret/server.key") + certificate, err := os.ReadFile(certPath) + if err != nil { + return err + } + key, err := os.ReadFile(keyPath) + if err != nil { + return err + } + cert, err := tls.X509KeyPair(certificate, key) + if err != nil { + return err + } + constant.CertStore.Store(&cert) + return nil +} + func loadInfoFromCert() (dto.SSLInfo, error) { var info dto.SSLInfo certFile := path.Join(global.CONF.System.BaseDir, "1panel/secret/server.crt") diff --git a/core/router/ro_setting.go b/core/router/ro_setting.go index ff7cd34f4..d3225d599 100644 --- a/core/router/ro_setting.go +++ b/core/router/ro_setting.go @@ -16,6 +16,8 @@ func (s *SettingRouter) InitRouter(Router *gin.RouterGroup) { Use(middleware.JwtAuth()). Use(middleware.SessionAuth()). Use(middleware.PasswordExpired()) + + noAuthRouter := Router.Group("settings") baseApi := v2.ApiGroupApp.BaseApi { router.POST("/search", baseApi.GetSettingInfo) @@ -39,5 +41,7 @@ func (s *SettingRouter) InitRouter(Router *gin.RouterGroup) { settingRouter.POST("/upgrade", baseApi.Upgrade) settingRouter.POST("/upgrade/notes", baseApi.GetNotesByVersion) settingRouter.GET("/upgrade", baseApi.GetUpgradeInfo) + + noAuthRouter.POST("/ssl/reload", baseApi.ReloadSSL) } } diff --git a/core/server/server.go b/core/server/server.go index b0802defb..d5db15f92 100644 --- a/core/server/server.go +++ b/core/server/server.go @@ -73,9 +73,11 @@ func Start() { if err != nil { panic(err) } + constant.CertStore.Store(&cert) + server.TLSConfig = &tls.Config{ GetCertificate: func(info *tls.ClientHelloInfo) (*tls.Certificate, error) { - return &cert, nil + return constant.CertStore.Load().(*tls.Certificate), nil }, } global.LOG.Infof("listen at https://%s:%s [%s]", global.CONF.System.BindAddress, global.CONF.System.Port, tcpItem) diff --git a/frontend/src/routers/router.ts b/frontend/src/routers/router.ts index 314a57f3f..fc319d367 100644 --- a/frontend/src/routers/router.ts +++ b/frontend/src/routers/router.ts @@ -72,6 +72,12 @@ export const routes: RouteRecordRaw[] = [ key: 'login', }, }, + { + path: '/:code?', + name: 'entrance', + component: () => import('@/views/login/entrance/index.vue'), + props: true, + }, ...routerArray, { path: '/:pathMatch(.*)', diff --git a/frontend/src/views/login/entrance/index.vue b/frontend/src/views/login/entrance/index.vue new file mode 100644 index 000000000..3b3fcbc5b --- /dev/null +++ b/frontend/src/views/login/entrance/index.vue @@ -0,0 +1,165 @@ + + + + +