1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-02-08 01:20:07 +08:00

fix: 拦截中间件数据改为实时获取 (#1213)

This commit is contained in:
ssongliu 2023-06-01 10:38:11 +08:00 committed by GitHub
parent bb48964cca
commit eb55e16465
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 47 additions and 48 deletions

View File

@ -114,10 +114,6 @@ func (u *SettingService) Update(key, value string) error {
if err := settingRepo.Update("ExpirationTime", time.Now().AddDate(0, 0, timeout).Format("2006-01-02 15:04:05")); err != nil { if err := settingRepo.Update("ExpirationTime", time.Now().AddDate(0, 0, timeout).Format("2006-01-02 15:04:05")); err != nil {
return err return err
} }
case "BindDomain":
global.CONF.System.BindDomain = value
case "AllowIPs":
global.CONF.System.AllowIPs = value
case "TimeZone": case "TimeZone":
go func() { go func() {
_, err := cmd.Exec("systemctl restart 1panel.service") _, err := cmd.Exec("systemctl restart 1panel.service")

View File

@ -21,6 +21,4 @@ type System struct {
IsDemo bool `mapstructure:"is_demo"` IsDemo bool `mapstructure:"is_demo"`
AppRepo string `mapstructure:"app_repo"` AppRepo string `mapstructure:"app_repo"`
ChangeUserInfo bool `mapstructure:"change_user_info"` ChangeUserInfo bool `mapstructure:"change_user_info"`
AllowIPs string `mapstructure:"allow_ips"`
BindDomain string `mapstructure:"bind_domain"`
} }

View File

@ -26,18 +26,6 @@ func Init() {
} }
global.CONF.System.SSL = sslSetting.Value global.CONF.System.SSL = sslSetting.Value
ipsSetting, err := settingRepo.Get(settingRepo.WithByKey("AllowIPs"))
if err != nil {
global.LOG.Errorf("load allow ips from setting failed, err: %v", err)
}
global.CONF.System.AllowIPs = ipsSetting.Value
domainSetting, err := settingRepo.Get(settingRepo.WithByKey("BindDomain"))
if err != nil {
global.LOG.Errorf("load bind domain from setting failed, err: %v", err)
}
global.CONF.System.BindDomain = domainSetting.Value
if _, err := settingRepo.Get(settingRepo.WithByKey("SystemStatus")); err != nil { if _, err := settingRepo.Get(settingRepo.WithByKey("SystemStatus")); err != nil {
_ = settingRepo.Create("SystemStatus", "Free") _ = settingRepo.Create("SystemStatus", "Free")
} }

View File

@ -5,14 +5,20 @@ import (
"strings" "strings"
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func BindDomain() gin.HandlerFunc { func BindDomain() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
if len(global.CONF.System.BindDomain) == 0 { settingRepo := repo.NewISettingRepo()
status, err := settingRepo.Get(settingRepo.WithByKey("BindDomain"))
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrDomain, constant.ErrTypeInternalServer, err)
return
}
if len(status.Value) == 0 {
c.Next() c.Next()
return return
} }
@ -22,7 +28,7 @@ func BindDomain() gin.HandlerFunc {
domains = parts[0] domains = parts[0]
} }
if domains != global.CONF.System.BindDomain { if domains != status.Value {
helper.ErrorWithDetail(c, constant.CodeErrDomain, constant.ErrTypeInternalServer, errors.New("domain not allowed")) helper.ErrorWithDetail(c, constant.CodeErrDomain, constant.ErrTypeInternalServer, errors.New("domain not allowed"))
return return
} }

View File

@ -5,19 +5,26 @@ import (
"strings" "strings"
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func WhiteAllow() gin.HandlerFunc { func WhiteAllow() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
if len(global.CONF.System.AllowIPs) == 0 { settingRepo := repo.NewISettingRepo()
status, err := settingRepo.Get(settingRepo.WithByKey("AllowIPs"))
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrIP, constant.ErrTypeInternalServer, err)
return
}
if len(status.Value) == 0 {
c.Next() c.Next()
return return
} }
clientIP := c.ClientIP() clientIP := c.ClientIP()
for _, ip := range strings.Split(global.CONF.System.AllowIPs, ",") { for _, ip := range strings.Split(status.Value, ",") {
if len(ip) != 0 && ip == clientIP { if len(ip) != 0 && ip == clientIP {
c.Next() c.Next()
return return

View File

@ -1003,7 +1003,7 @@ const message = {
'After setting the authorized IP address, only the IP address in the setting can access the 1Panel service. Do you want to continue?', 'After setting the authorized IP address, only the IP address in the setting can access the 1Panel service. Do you want to continue?',
allowIPsHelper1: 'If the authorized IP address is empty, the authorized IP address is canceled', allowIPsHelper1: 'If the authorized IP address is empty, the authorized IP address is canceled',
allowIPEgs: allowIPEgs:
'If multiple ip authorizations exist, newlines need to be displayed. For example, \n172.16.10.111 \n172.16.10.111', 'If multiple ip authorizations exist, newlines need to be displayed. For example, \n172.16.10.111 \n172.16.10.112',
mfa: 'MFA', mfa: 'MFA',
mfaAlert: mfaAlert:
'MFA password is generated based on the current time. Please ensure that the server time is synchronized.', 'MFA password is generated based on the current time. Please ensure that the server time is synchronized.',

View File

@ -1016,7 +1016,7 @@ const message = {
allowIPsHelper: '设置授权 IP 仅有设置中的 IP 可以访问 1Panel 服务', allowIPsHelper: '设置授权 IP 仅有设置中的 IP 可以访问 1Panel 服务',
allowIPsWarnning: '设置授权 IP 仅有设置中的 IP 可以访问 1Panel 服务是否继续', allowIPsWarnning: '设置授权 IP 仅有设置中的 IP 可以访问 1Panel 服务是否继续',
allowIPsHelper1: '授权 IP 为空时则取消授权 IP', allowIPsHelper1: '授权 IP 为空时则取消授权 IP',
allowIPEgs: '当存在多个授权 IP 需要换行显示 \n172.16.10.111 \n172.16.10.111', allowIPEgs: '当存在多个授权 IP 需要换行显示 \n172.16.10.111 \n172.16.10.112',
mfa: '两步验证', mfa: '两步验证',
mfaAlert: '两步验证密码是基于当前时间生成请确保服务器时间已同步', mfaAlert: '两步验证密码是基于当前时间生成请确保服务器时间已同步',
mfaHelper: '开启后会验证手机应用验证码', mfaHelper: '开启后会验证手机应用验证码',

View File

@ -56,11 +56,15 @@ const mySafetyCode = defineProps({
const getStatus = async () => { const getStatus = async () => {
isErr.value = true; isErr.value = true;
const res = await checkIsSafety(mySafetyCode.code); let code = mySafetyCode.code;
if (code === 'err-ip' || code === 'err-domain') {
code = globalStore.entrance;
}
const res = await checkIsSafety(code);
isErr.value = false; isErr.value = false;
globalStore.entrance = ''; globalStore.entrance = '';
if (res.data === 'disable') { if (res.data === 'disable') {
if (mySafetyCode.code === '') { if (code === '') {
isNotFound.value = false; isNotFound.value = false;
} else { } else {
isNotFound.value = true; isNotFound.value = true;
@ -73,7 +77,7 @@ const getStatus = async () => {
return; return;
} }
if (res.data === 'pass') { if (res.data === 'pass') {
globalStore.entrance = mySafetyCode.code; globalStore.entrance = code;
} }
}; };