mirror of
https://github.com/acepanel/panel.git
synced 2026-02-03 20:50:00 +08:00
feat: 将session超时写入主配置
This commit is contained in:
@@ -11,3 +11,5 @@ http:
|
||||
tls: true
|
||||
database:
|
||||
debug: false
|
||||
session:
|
||||
lifetime: 120
|
||||
|
||||
@@ -11,7 +11,7 @@ func NewSession(conf *koanf.Koanf, db *gorm.DB) (*sessions.Manager, error) {
|
||||
// initialize session manager
|
||||
manager, err := sessions.NewManager(&sessions.ManagerOptions{
|
||||
Key: conf.MustString("app.key"),
|
||||
Lifetime: 120,
|
||||
Lifetime: conf.MustInt("session.lifetime"),
|
||||
GcInterval: 5,
|
||||
DisableDefaultDriver: true,
|
||||
})
|
||||
|
||||
@@ -179,10 +179,6 @@ func (r *settingRepo) GetPanelSetting(ctx context.Context) (*request.PanelSettin
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
loginTimeout, err := r.GetInt(biz.SettingKeyLoginTimeout)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bindDomain, err := r.GetSlice(biz.SettingKeyBindDomain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -235,7 +231,7 @@ func (r *settingRepo) GetPanelSetting(ctx context.Context) (*request.PanelSettin
|
||||
OfflineMode: offlineMode,
|
||||
AutoUpdate: autoUpdate,
|
||||
TwoFA: twoFA,
|
||||
LoginTimeout: loginTimeout,
|
||||
Lifetime: uint(r.conf.Int("session.lifetime")),
|
||||
BindDomain: bindDomain,
|
||||
BindIP: bindIP,
|
||||
BindUA: bindUA,
|
||||
@@ -265,9 +261,6 @@ func (r *settingRepo) UpdatePanelSetting(ctx context.Context, setting *request.P
|
||||
if err := r.Set(biz.SettingKeyAutoUpdate, cast.ToString(setting.AutoUpdate)); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if err := r.Set(biz.SettingKeyLoginTimeout, cast.ToString(setting.LoginTimeout)); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if err := r.Set(biz.SettingKeyTwoFA, cast.ToString(setting.TwoFA)); err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -351,6 +344,7 @@ func (r *settingRepo) UpdatePanelSetting(ctx context.Context, setting *request.P
|
||||
config.HTTP.Port = setting.Port
|
||||
config.HTTP.Entrance = setting.Entrance
|
||||
config.HTTP.TLS = setting.HTTPS
|
||||
config.Session.Lifetime = setting.Lifetime
|
||||
|
||||
// 放行端口
|
||||
fw := firewall.NewFirewall()
|
||||
|
||||
@@ -8,7 +8,7 @@ type PanelSetting struct {
|
||||
OfflineMode bool `json:"offline_mode"`
|
||||
AutoUpdate bool `json:"auto_update"`
|
||||
TwoFA bool `json:"two_fa"`
|
||||
LoginTimeout int `json:"login_timeout" validate:"required|min:10|max:43200"` // 登录超时,单位:分
|
||||
Lifetime uint `json:"lifetime" validate:"required|min:10|max:43200"` // 登录超时,单位:分
|
||||
BindDomain []string `json:"bind_domain"`
|
||||
BindIP []string `json:"bind_ip"`
|
||||
BindUA []string `json:"bind_ua"`
|
||||
|
||||
@@ -5,6 +5,7 @@ type PanelConfig struct {
|
||||
App PanelAppConfig `yaml:"app"`
|
||||
HTTP PanelHTTPConfig `yaml:"http"`
|
||||
Database PanelDatabaseConfig `yaml:"database"`
|
||||
Session PanelSessionConfig `yaml:"session"`
|
||||
}
|
||||
|
||||
type PanelAppConfig struct {
|
||||
@@ -25,3 +26,7 @@ type PanelHTTPConfig struct {
|
||||
type PanelDatabaseConfig struct {
|
||||
Debug bool `yaml:"debug"`
|
||||
}
|
||||
|
||||
type PanelSessionConfig struct {
|
||||
Lifetime uint `yaml:"lifetime"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user