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

pull/1214/head
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 {
return err
}
case "BindDomain":
global.CONF.System.BindDomain = value
case "AllowIPs":
global.CONF.System.AllowIPs = value
case "TimeZone":
go func() {
_, err := cmd.Exec("systemctl restart 1panel.service")

View File

@ -1,26 +1,24 @@
package configs
type System struct {
Port string `mapstructure:"port"`
SSL string `mapstructure:"ssl"`
DbFile string `mapstructure:"db_file"`
DbPath string `mapstructure:"db_path"`
LogPath string `mapstructure:"log_path"`
DataDir string `mapstructure:"data_dir"`
TmpDir string `mapstructure:"tmp_dir"`
Cache string `mapstructure:"cache"`
Backup string `mapstructure:"backup"`
EncryptKey string `mapstructure:"encrypt_key"`
BaseDir string `mapstructure:"base_dir"`
Mode string `mapstructure:"mode"`
RepoUrl string `mapstructure:"repo_url"`
Version string `mapstructure:"version"`
Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
Entrance string `mapstructure:"entrance"`
IsDemo bool `mapstructure:"is_demo"`
AppRepo string `mapstructure:"app_repo"`
Port string `mapstructure:"port"`
SSL string `mapstructure:"ssl"`
DbFile string `mapstructure:"db_file"`
DbPath string `mapstructure:"db_path"`
LogPath string `mapstructure:"log_path"`
DataDir string `mapstructure:"data_dir"`
TmpDir string `mapstructure:"tmp_dir"`
Cache string `mapstructure:"cache"`
Backup string `mapstructure:"backup"`
EncryptKey string `mapstructure:"encrypt_key"`
BaseDir string `mapstructure:"base_dir"`
Mode string `mapstructure:"mode"`
RepoUrl string `mapstructure:"repo_url"`
Version string `mapstructure:"version"`
Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
Entrance string `mapstructure:"entrance"`
IsDemo bool `mapstructure:"is_demo"`
AppRepo string `mapstructure:"app_repo"`
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
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 {
_ = settingRepo.Create("SystemStatus", "Free")
}

View File

@ -5,14 +5,20 @@ import (
"strings"
"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/global"
"github.com/gin-gonic/gin"
)
func BindDomain() gin.HandlerFunc {
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()
return
}
@ -22,7 +28,7 @@ func BindDomain() gin.HandlerFunc {
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"))
return
}

View File

@ -5,19 +5,26 @@ import (
"strings"
"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/global"
"github.com/gin-gonic/gin"
)
func WhiteAllow() gin.HandlerFunc {
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()
return
}
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 {
c.Next()
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?',
allowIPsHelper1: 'If the authorized IP address is empty, the authorized IP address is canceled',
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',
mfaAlert:
'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 ',
allowIPsWarnning: ' IP IP 访 1Panel ',
allowIPsHelper1: ' IP IP',
allowIPEgs: ' IP \n172.16.10.111 \n172.16.10.111',
allowIPEgs: ' IP \n172.16.10.111 \n172.16.10.112',
mfa: '',
mfaAlert: '',
mfaHelper: '',

View File

@ -56,11 +56,15 @@ const mySafetyCode = defineProps({
const getStatus = async () => {
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;
globalStore.entrance = '';
if (res.data === 'disable') {
if (mySafetyCode.code === '') {
if (code === '') {
isNotFound.value = false;
} else {
isNotFound.value = true;
@ -73,7 +77,7 @@ const getStatus = async () => {
return;
}
if (res.data === 'pass') {
globalStore.entrance = mySafetyCode.code;
globalStore.entrance = code;
}
};