2023-02-21 15:19:12 +08:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
2023-09-28 16:16:17 +08:00
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
2023-02-21 15:19:12 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/buserr"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
var whiteUrlList = map[string]struct{}{
|
|
|
|
"/api/v1/auth/login": {},
|
|
|
|
"/api/v1/websites/config": {},
|
|
|
|
"/api/v1/websites/waf/config": {},
|
|
|
|
"/api/v1/files/loadfile": {},
|
|
|
|
"/api/v1/files/size": {},
|
|
|
|
"/api/v1/logs/operation": {},
|
|
|
|
"/api/v1/logs/login": {},
|
|
|
|
"/api/v1/auth/logout": {},
|
2023-09-28 16:16:17 +08:00
|
|
|
|
|
|
|
"/api/v1/apps/installed/loadport": {},
|
|
|
|
"/api/v1/apps/installed/check": {},
|
|
|
|
"/api/v1/apps/installed/conninfo": {},
|
|
|
|
"/api/v1/databases/load/file": {},
|
|
|
|
"/api/v1/databases/variables": {},
|
|
|
|
"/api/v1/databases/status": {},
|
|
|
|
"/api/v1/databases/baseinfo": {},
|
2024-04-28 22:10:44 +08:00
|
|
|
|
|
|
|
"/api/v1/waf/attack/stat": {},
|
|
|
|
"/api/v1/waf/config/website": {},
|
2023-02-21 15:19:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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(constant.ErrDemoEnvironment).Error(),
|
|
|
|
})
|
|
|
|
c.Abort()
|
|
|
|
}
|
|
|
|
}
|