mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-22 16:00:51 +00:00
* feat: Implement caching for settings retrieval and update logic - Introduced a caching mechanism for settings using go-cache to improve performance. - Updated the Create, Update, and UpdateOrCreate methods to cache values after database operations. - Modified the Get and GetValueByKey methods to utilize the cache for faster access. - Adjusted middleware to use the new GetValueByKey method for retrieving settings, enhancing code consistency. * feat: Enhance setting cache management with dynamic TTL - Introduced a function to determine cache TTL based on setting keys, allowing critical settings to have shorter cache durations. - Updated cache logic in Create, Update, Get, and GetValueByKey methods to utilize the new TTL management, improving performance and consistency in settings retrieval. * refactor: Simplify setting cache TTL management - Removed the dynamic TTL function and standardized the cache TTL to a fixed duration for all settings. - Updated cache logic in Create, Update, Get, and GetValueByKey methods to use the new fixed TTL, enhancing code clarity and maintainability. - Added a new function to restart the core service after resetting settings, improving the reset command's functionality. * refactor: Remove core restart functionality from reset commands - Eliminated the restartCoreAfterReset function to simplify the reset command logic. - Updated reset commands to return nil after setting changes, enhancing clarity and reducing unnecessary complexity.
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package middleware
|
|
|
|
import (
|
|
"github.com/1Panel-dev/1Panel/core/utils/common"
|
|
"strings"
|
|
|
|
"github.com/1Panel-dev/1Panel/core/app/api/v2/helper"
|
|
"github.com/1Panel-dev/1Panel/core/app/repo"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func WhiteAllow() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
tokenString := c.GetHeader("X-Panel-Local-Token")
|
|
clientIP := common.GetRealClientIP(c)
|
|
if clientIP == "127.0.0.1" && tokenString != "" && c.Request.URL.Path == "/api/v2/core/xpack/sync/ssl" {
|
|
c.Set("LOCAL_REQUEST", true)
|
|
c.Next()
|
|
return
|
|
}
|
|
if common.IsPrivateIP(clientIP) {
|
|
c.Next()
|
|
return
|
|
}
|
|
|
|
settingRepo := repo.NewISettingRepo()
|
|
allowIPs, err := settingRepo.GetValueByKey("AllowIPs")
|
|
if err != nil {
|
|
helper.InternalServer(c, err)
|
|
return
|
|
}
|
|
|
|
if len(allowIPs) == 0 {
|
|
c.Next()
|
|
return
|
|
}
|
|
for _, ip := range strings.Split(allowIPs, ",") {
|
|
if len(ip) == 0 {
|
|
continue
|
|
}
|
|
if ip == clientIP || (strings.Contains(ip, "/") && common.CheckIpInCidr(ip, clientIP)) {
|
|
c.Next()
|
|
return
|
|
}
|
|
}
|
|
code := LoadErrCode()
|
|
helper.ErrWithHtml(c, code, "err_ip_limit")
|
|
}
|
|
}
|