diff --git a/web/assets/js/model/models.js b/web/assets/js/model/models.js
index ace99f48..a3fd2633 100644
--- a/web/assets/js/model/models.js
+++ b/web/assets/js/model/models.js
@@ -172,6 +172,7 @@ class AllSetting {
this.webCertFile = "";
this.webKeyFile = "";
this.webBasePath = "/";
+ this.sessionMaxAge = "";
this.expireDiff = "";
this.trafficDiff = "";
this.tgBotEnable = false;
diff --git a/web/controller/index.go b/web/controller/index.go
index c19ee799..4776cefa 100644
--- a/web/controller/index.go
+++ b/web/controller/index.go
@@ -70,6 +70,16 @@ func (a *IndexController) login(c *gin.Context) {
} else {
logger.Infof("%s login success,Ip Address:%s\n", form.Username, getRemoteIp(c))
a.tgbot.UserLoginNotify(form.Username, getRemoteIp(c), timeStr, 1)
+ sessionMaxAge, err := a.settingService.GetSessionMaxAge()
+ if err != nil {
+ logger.Infof("Unable to get session's max age from DB")
+ }
+
+ err = session.SetMaxAge(c, sessionMaxAge*60)
+ if err != nil {
+ logger.Infof("Unable to set session's max age")
+ }
+
}
err = session.SetLoginUser(c, user)
diff --git a/web/entity/entity.go b/web/entity/entity.go
index f1b24520..b370b7ba 100644
--- a/web/entity/entity.go
+++ b/web/entity/entity.go
@@ -32,6 +32,7 @@ type AllSetting struct {
WebCertFile string `json:"webCertFile" form:"webCertFile"`
WebKeyFile string `json:"webKeyFile" form:"webKeyFile"`
WebBasePath string `json:"webBasePath" form:"webBasePath"`
+ SessionMaxAge int `json:"sessionMaxAge" form:"sessionMaxAge"`
ExpireDiff int `json:"expireDiff" form:"expireDiff"`
TrafficDiff int `json:"trafficDiff" form:"trafficDiff"`
TgBotEnable bool `json:"tgBotEnable" form:"tgBotEnable"`
diff --git a/web/html/xui/component/setting.html b/web/html/xui/component/setting.html
index 9f8e8cbc..00eeb259 100644
--- a/web/html/xui/component/setting.html
+++ b/web/html/xui/component/setting.html
@@ -9,7 +9,7 @@
-
+
@@ -25,7 +25,7 @@
{{define "component/setting"}}
diff --git a/web/html/xui/setting.html b/web/html/xui/setting.html
index c5ee6c54..0ab9da96 100644
--- a/web/html/xui/setting.html
+++ b/web/html/xui/setting.html
@@ -45,6 +45,7 @@
+
diff --git a/web/service/setting.go b/web/service/setting.go
index 6e305536..d3072252 100644
--- a/web/service/setting.go
+++ b/web/service/setting.go
@@ -29,6 +29,7 @@ var defaultValueMap = map[string]string{
"webKeyFile": "",
"secret": random.Seq(32),
"webBasePath": "/",
+ "sessionMaxAge": "0",
"expireDiff": "0",
"trafficDiff": "0",
"timeLocation": "Asia/Tehran",
@@ -251,18 +252,10 @@ func (s *SettingService) GetTgBotBackup() (bool, error) {
return s.getBool("tgBotBackup")
}
-func (s *SettingService) SetTgBotBackup(value bool) error {
- return s.setBool("tgBotBackup", value)
-}
-
func (s *SettingService) GetTgCpu() (int, error) {
return s.getInt("tgCpu")
}
-func (s *SettingService) SetTgCpu(value int) error {
- return s.setInt("tgCpu", value)
-}
-
func (s *SettingService) GetPort() (int, error) {
return s.getInt("webPort")
}
@@ -283,16 +276,12 @@ func (s *SettingService) GetExpireDiff() (int, error) {
return s.getInt("expireDiff")
}
-func (s *SettingService) SetExpireDiff(value int) error {
- return s.setInt("expireDiff", value)
-}
-
func (s *SettingService) GetTrafficDiff() (int, error) {
return s.getInt("trafficDiff")
}
-func (s *SettingService) SetgetTrafficDiff(value int) error {
- return s.setInt("trafficDiff", value)
+func (s *SettingService) GetSessionMaxAge() (int, error) {
+ return s.getInt("sessionMaxAge")
}
func (s *SettingService) GetSecretStatus() (bool, error) {
diff --git a/web/session/session.go b/web/session/session.go
index 2dfe94b6..ea04d0f9 100644
--- a/web/session/session.go
+++ b/web/session/session.go
@@ -2,9 +2,10 @@ package session
import (
"encoding/gob"
+ "x-ui/database/model"
+
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
- "x-ui/database/model"
)
const (
@@ -21,6 +22,15 @@ func SetLoginUser(c *gin.Context, user *model.User) error {
return s.Save()
}
+func SetMaxAge(c *gin.Context, maxAge int) error {
+ s := sessions.Default(c)
+ s.Options(sessions.Options{
+ Path: "/",
+ MaxAge: maxAge,
+ })
+ return s.Save()
+}
+
func GetLoginUser(c *gin.Context) *model.User {
s := sessions.Default(c)
obj := s.Get(loginUser)
diff --git a/web/translation/translate.en_US.toml b/web/translation/translate.en_US.toml
index 70bf8251..48252b7b 100644
--- a/web/translation/translate.en_US.toml
+++ b/web/translation/translate.en_US.toml
@@ -281,6 +281,8 @@
"telegramNotifyTimeDesc" = "Using Crontab timing format. Restart the panel to take effect"
"tgNotifyBackup" = "Database backup"
"tgNotifyBackupDesc" = "Sending database backup file with report notification. Restart the panel to take effect"
+"sessionMaxAge" = "Session maximum age"
+"sessionMaxAgeDesc" = "The time that you can stay login (unit: minute)"
"expireTimeDiff" = "Exhaustion time threshold"
"expireTimeDiffDesc" = "Detect exhaustion before expiration (unit:day)"
"trafficDiff" = "Exhaustion traffic threshold"
diff --git a/web/translation/translate.fa_IR.toml b/web/translation/translate.fa_IR.toml
index 28ed1747..ec21d582 100644
--- a/web/translation/translate.fa_IR.toml
+++ b/web/translation/translate.fa_IR.toml
@@ -279,6 +279,8 @@
"telegramNotifyTimeDesc" = "از فرمت زمان بندی لینوکس استفاده کنید . پنل را مجدداً راه اندازی کنید تا اعمال شود"
"tgNotifyBackup" = "پشتیبان گیری از پایگاه داده"
"tgNotifyBackupDesc" = "ارسال کپی فایل پایگاه داده به همراه گزارش دوره ای"
+"sessionMaxAge" = "بیشینه زمان جلسه وب"
+"sessionMaxAgeDesc" = "بیشینه زمانی که میتوانید لاگین بمانید (واحد: دقیقه)"
"expireTimeDiff" = "آستانه زمان باقی مانده"
"expireTimeDiffDesc" = "فاصله زمانی هشدار تا رسیدن به زمان انقضا (واحد: روز)"
"trafficDiff" = "آستانه ترافیک باقی مانده"
diff --git a/web/translation/translate.zh_Hans.toml b/web/translation/translate.zh_Hans.toml
index f79ce75f..09a54247 100644
--- a/web/translation/translate.zh_Hans.toml
+++ b/web/translation/translate.zh_Hans.toml
@@ -279,6 +279,8 @@
"telegramNotifyTimeDesc" = "采用Crontab定时格式,重启面板生效"
"tgNotifyBackup" = "数据库备份"
"tgNotifyBackupDesc" = "正在发送数据库备份文件和报告通知。重启面板生效"
+"sessionMaxAge" = "会话最大年龄"
+"sessionMaxAgeDesc" = "您可以保持登录状态的时间(单位:分钟)"
"expireTimeDiff" = "耗尽时间阈值"
"expireTimeDiffDesc" = "到期前检测耗尽(单位:天)"
"trafficDiff" = "耗尽流量阈值"