feat: update demo handle (#9175)

This commit is contained in:
CityFun 2025-06-18 17:58:56 +08:00 committed by GitHub
parent 420537f092
commit 4032276556
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 59 deletions

View file

@ -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()
}
}

View file

@ -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) {

View file

@ -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"`
}

View file

@ -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
}