Compare commits

..

5 commits

Author SHA1 Message Date
Vadim Iskuchekov
e0664b29d4
Merge 09933f845d into 311d11a3c1 2025-09-12 13:27:07 +02:00
mhsanaei
311d11a3c1
cookie: MaxAge
Some checks are pending
Release 3X-UI / build (386) (push) Waiting to run
Release 3X-UI / build (amd64) (push) Waiting to run
Release 3X-UI / build (arm64) (push) Waiting to run
Release 3X-UI / build (armv5) (push) Waiting to run
Release 3X-UI / build (armv6) (push) Waiting to run
Release 3X-UI / build (armv7) (push) Waiting to run
Release 3X-UI / build (s390x) (push) Waiting to run
Release 3X-UI / Build for Windows (push) Waiting to run
and minor changes
2025-09-12 13:04:36 +02:00
Sanaei
09933f845d
Update web/service/inbound.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-09-12 12:30:53 +02:00
Sanaei
7f4efbd92e
Update web/job/periodic_client_traffic_reset_job.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-09-12 12:30:36 +02:00
Sanaei
6e263fff8a
Update web/job/periodic_traffic_reset_job.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-09-12 12:30:23 +02:00
5 changed files with 23 additions and 6 deletions

View file

@ -37,6 +37,6 @@ func (j *PeriodicClientTrafficResetJob) Run() {
}
if resetCount > 0 {
logger.Infof("Periodic client traffic reset completed: %d clients reseted", resetCount)
logger.Infof("Periodic client traffic reset completed: %d clients reset", resetCount)
}
}

View file

@ -39,6 +39,6 @@ func (j *PeriodicTrafficResetJob) Run() {
}
if resetCount > 0 {
logger.Infof("Periodic traffic reset completed: %d inbounds reseted", resetCount)
logger.Infof("Periodic traffic reset completed: %d inbounds reset", resetCount)
}
}

View file

@ -739,7 +739,7 @@ func (s *InboundService) DelInboundClient(inboundId int, clientId string) (bool,
}
func (s *InboundService) UpdateInboundClient(data *model.Inbound, clientId string) (bool, error) {
// TODO: check if TrafficReset field are updating
// TODO: check if TrafficReset field is updating
clients, err := s.GetClients(data)
if err != nil {
return false, err

View file

@ -2,6 +2,7 @@ package session
import (
"encoding/gob"
"net/http"
"x-ui/database/model"
@ -32,6 +33,7 @@ func SetMaxAge(c *gin.Context, maxAge int) {
Path: defaultPath,
MaxAge: maxAge,
HttpOnly: true,
SameSite: http.SameSiteLaxMode,
})
}
@ -61,5 +63,6 @@ func ClearSession(c *gin.Context) {
Path: defaultPath,
MaxAge: -1,
HttpOnly: true,
SameSite: http.SameSiteLaxMode,
})
}

View file

@ -31,7 +31,7 @@ import (
"github.com/robfig/cron/v3"
)
//go:embed assets/*
//go:embed assets
var assetsFS embed.FS
//go:embed html/*
@ -180,6 +180,15 @@ func (s *Server) initRouter() (*gin.Engine, error) {
assetsBasePath := basePath + "assets/"
store := cookie.NewStore(secret)
// Configure default session cookie options, including expiration (MaxAge)
if sessionMaxAge, err := s.settingService.GetSessionMaxAge(); err == nil {
store.Options(sessions.Options{
Path: "/",
MaxAge: sessionMaxAge * 60, // minutes -> seconds
HttpOnly: true,
SameSite: http.SameSiteLaxMode,
})
}
engine.Use(sessions.Sessions("3x-ui", store))
engine.Use(func(c *gin.Context) {
c.Set("base_path", basePath)
@ -201,7 +210,11 @@ func (s *Server) initRouter() (*gin.Engine, error) {
i18nWebFunc := func(key string, params ...string) string {
return locale.I18n(locale.Web, key, params...)
}
engine.FuncMap["i18n"] = i18nWebFunc
// Register template functions before loading templates
funcMap := template.FuncMap{
"i18n": i18nWebFunc,
}
engine.SetFuncMap(funcMap)
engine.Use(locale.LocalizerMiddleware())
// set static files and template
@ -211,11 +224,12 @@ func (s *Server) initRouter() (*gin.Engine, error) {
if err != nil {
return nil, err
}
// Use the registered func map with the loaded templates
engine.LoadHTMLFiles(files...)
engine.StaticFS(basePath+"assets", http.FS(os.DirFS("web/assets")))
} else {
// for production
template, err := s.getHtmlTemplate(engine.FuncMap)
template, err := s.getHtmlTemplate(funcMap)
if err != nil {
return nil, err
}