From 4032276556e3795c0e481fe2e8ddf24a98545e55 Mon Sep 17 00:00:00 2001 From: CityFun <31820853+zhengkunwang223@users.noreply.github.com> Date: Wed, 18 Jun 2025 17:58:56 +0800 Subject: [PATCH] feat: update demo handle (#9175) --- agent/middleware/demo_handle.go | 57 --------------------------------- core/app/api/v2/auth.go | 11 ++++++- core/app/dto/setting.go | 9 ++++++ core/middleware/demo_handle.go | 11 ++++++- 4 files changed, 29 insertions(+), 59 deletions(-) delete mode 100644 agent/middleware/demo_handle.go diff --git a/agent/middleware/demo_handle.go b/agent/middleware/demo_handle.go deleted file mode 100644 index 9e46bf983..000000000 --- a/agent/middleware/demo_handle.go +++ /dev/null @@ -1,57 +0,0 @@ -package middleware - -import ( - "net/http" - "strings" - - "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/buserr" - "github.com/gin-gonic/gin" -) - -var whiteUrlList = map[string]struct{}{ - "/api/v2/auth/login": {}, - "/api/v2/websites/config": {}, - "/api/v2/websites/waf/config": {}, - "/api/v2/files/loadfile": {}, - "/api/v2/files/size": {}, - "/api/v2/logs/operation": {}, - "/api/v2/logs/login": {}, - "/api/v2/auth/logout": {}, - "/api/v1/dashboard/current": {}, - - "/api/v2/apps/installed/loadport": {}, - "/api/v2/apps/installed/check": {}, - "/api/v2/apps/installed/conninfo": {}, - "/api/v2/databases/load/file": {}, - "/api/v2/databases/variables": {}, - "/api/v2/databases/status": {}, - "/api/v2/databases/baseinfo": {}, - - "/api/v2/waf/attack/stat": {}, - "/api/v2/waf/config/website": {}, - - "/api/v2/monitor/stat": {}, - "/api/v2/monitor/visitors": {}, - "/api/v2/monitor/visitors/loc": {}, - "/api/v2/monitor/qps": {}, -} - -func DemoHandle() gin.HandlerFunc { - return func(c *gin.Context) { - if strings.Contains(c.Request.URL.Path, "search") || c.Request.Method == http.MethodGet { - c.Next() - return - } - if _, ok := whiteUrlList[c.Request.URL.Path]; ok { - c.Next() - return - } - - c.JSON(http.StatusInternalServerError, dto.Response{ - Code: http.StatusInternalServerError, - Message: buserr.New("ErrDemoEnvironment").Error(), - }) - c.Abort() - } -} diff --git a/core/app/api/v2/auth.go b/core/app/api/v2/auth.go index d13c1528c..d1eb03a71 100644 --- a/core/app/api/v2/auth.go +++ b/core/app/api/v2/auth.go @@ -6,6 +6,7 @@ import ( "github.com/1Panel-dev/1Panel/core/app/dto" "github.com/1Panel-dev/1Panel/core/app/model" "github.com/1Panel-dev/1Panel/core/constant" + "github.com/1Panel-dev/1Panel/core/global" "github.com/1Panel-dev/1Panel/core/utils/captcha" "github.com/gin-gonic/gin" ) @@ -133,7 +134,15 @@ func (b *BaseApi) GetLoginSetting(c *gin.Context) { helper.InternalServer(c, err) return } - helper.SuccessWithData(c, settingInfo) + res := &dto.LoginSetting{ + IsDemo: global.CONF.Base.IsDemo, + IsIntl: global.CONF.Base.IsIntl, + Language: settingInfo.Language, + MenuTabs: settingInfo.MenuTabs, + PanelName: settingInfo.PanelName, + Theme: settingInfo.Theme, + } + helper.SuccessWithData(c, res) } func saveLoginLogs(c *gin.Context, err error) { diff --git a/core/app/dto/setting.go b/core/app/dto/setting.go index 9af52037e..931b3f0ce 100644 --- a/core/app/dto/setting.go +++ b/core/app/dto/setting.go @@ -219,3 +219,12 @@ type AppstoreConfig struct { UpgradeBackup string `json:"upgradeBackup"` UninstallDeleteBackup string `json:"uninstallDeleteBackup"` } + +type LoginSetting struct { + IsDemo bool `json:"isDemo"` + IsIntl bool `json:"isIntl"` + Language string `json:"language"` + MenuTabs string `json:"menuTabs"` + PanelName string `json:"panelName"` + Theme string `json:"theme"` +} diff --git a/core/middleware/demo_handle.go b/core/middleware/demo_handle.go index 29bb2d637..532d75f8f 100644 --- a/core/middleware/demo_handle.go +++ b/core/middleware/demo_handle.go @@ -17,6 +17,12 @@ var whiteUrlList = map[string]struct{}{ "/api/v2/files/size": {}, "/api/v2/runtimes/sync": {}, "/api/v2/toolbox/device/base": {}, + "/api/v2/files/user/group": {}, + "/api/v2/files/mount": {}, + "/api/v2/hosts/ssh/log": {}, + "/api/v2/toolbox/clam/base": {}, + "/api/v2/hosts/too": {}, + "/api/v2/backups/record/size": {}, "/api/v2/core/auth/login": {}, "/api/v2/core/logs/login": {}, @@ -43,11 +49,14 @@ var whiteUrlList = map[string]struct{}{ "/api/v2/xpack/monitor/websites": {}, "/api/v2/xpack/monitor/trend": {}, "/api/v2/xpack/monitor/rank": {}, + "/api/v2/xpack/waf/cdn": {}, + + "/api/v2/core/nodes/list": {}, } func DemoHandle() gin.HandlerFunc { return func(c *gin.Context) { - if strings.Contains(c.Request.URL.Path, "search") || c.Request.Method == http.MethodGet { + if strings.Contains(c.Request.URL.Path, "search") || (c.Request.Method == http.MethodGet && c.Request.URL.Path != "/api/v2/containers/exec") { c.Next() return }