mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-02-07 17:10:07 +08:00
fix: 拦截中间件数据改为实时获取 (#1213)
This commit is contained in:
parent
bb48964cca
commit
eb55e16465
@ -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")
|
||||||
|
@ -1,26 +1,24 @@
|
|||||||
package configs
|
package configs
|
||||||
|
|
||||||
type System struct {
|
type System struct {
|
||||||
Port string `mapstructure:"port"`
|
Port string `mapstructure:"port"`
|
||||||
SSL string `mapstructure:"ssl"`
|
SSL string `mapstructure:"ssl"`
|
||||||
DbFile string `mapstructure:"db_file"`
|
DbFile string `mapstructure:"db_file"`
|
||||||
DbPath string `mapstructure:"db_path"`
|
DbPath string `mapstructure:"db_path"`
|
||||||
LogPath string `mapstructure:"log_path"`
|
LogPath string `mapstructure:"log_path"`
|
||||||
DataDir string `mapstructure:"data_dir"`
|
DataDir string `mapstructure:"data_dir"`
|
||||||
TmpDir string `mapstructure:"tmp_dir"`
|
TmpDir string `mapstructure:"tmp_dir"`
|
||||||
Cache string `mapstructure:"cache"`
|
Cache string `mapstructure:"cache"`
|
||||||
Backup string `mapstructure:"backup"`
|
Backup string `mapstructure:"backup"`
|
||||||
EncryptKey string `mapstructure:"encrypt_key"`
|
EncryptKey string `mapstructure:"encrypt_key"`
|
||||||
BaseDir string `mapstructure:"base_dir"`
|
BaseDir string `mapstructure:"base_dir"`
|
||||||
Mode string `mapstructure:"mode"`
|
Mode string `mapstructure:"mode"`
|
||||||
RepoUrl string `mapstructure:"repo_url"`
|
RepoUrl string `mapstructure:"repo_url"`
|
||||||
Version string `mapstructure:"version"`
|
Version string `mapstructure:"version"`
|
||||||
Username string `mapstructure:"username"`
|
Username string `mapstructure:"username"`
|
||||||
Password string `mapstructure:"password"`
|
Password string `mapstructure:"password"`
|
||||||
Entrance string `mapstructure:"entrance"`
|
Entrance string `mapstructure:"entrance"`
|
||||||
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"`
|
|
||||||
}
|
}
|
||||||
|
@ -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")
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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.',
|
||||||
|
@ -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: '开启后会验证手机应用验证码',
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user