mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 00:09:16 +08:00
feat: Optimize Location Information Display in System Login Logs (#7459)
This commit is contained in:
parent
e83d07e88e
commit
69ad01687e
@ -8,8 +8,6 @@ import (
|
||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||
"github.com/1Panel-dev/1Panel/backend/global"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/captcha"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/common"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/geo"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -157,11 +155,6 @@ func saveLoginLogs(c *gin.Context, err error) {
|
||||
logs.Status = constant.StatusSuccess
|
||||
}
|
||||
logs.IP = c.ClientIP()
|
||||
address, err := geo.GetIPLocation(logs.IP, common.GetLang(c))
|
||||
if err != nil {
|
||||
global.LOG.Errorf("get ip location failed: %s", err)
|
||||
}
|
||||
logs.Agent = c.GetHeader("User-Agent")
|
||||
logs.Address = address
|
||||
_ = logService.CreateLoginLog(logs)
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ func (b *BaseApi) GetLoginLogs(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
total, list, err := logService.PageLoginLog(req)
|
||||
total, list, err := logService.PageLoginLog(c, req)
|
||||
if err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||
return
|
||||
|
@ -2,6 +2,9 @@ package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/common"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/geo"
|
||||
"github.com/gin-gonic/gin"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@ -26,7 +29,7 @@ const logs = "https://resource.fit2cloud.com/installation-log.sh"
|
||||
type ILogService interface {
|
||||
ListSystemLogFile() ([]string, error)
|
||||
CreateLoginLog(operation model.LoginLog) error
|
||||
PageLoginLog(search dto.SearchLgLogWithPage) (int64, interface{}, error)
|
||||
PageLoginLog(c *gin.Context, search dto.SearchLgLogWithPage) (int64, interface{}, error)
|
||||
|
||||
CreateOperationLog(operation model.OperationLog) error
|
||||
PageOperationLog(search dto.SearchOpLogWithPage) (int64, interface{}, error)
|
||||
@ -77,7 +80,7 @@ func (u *LogService) ListSystemLogFile() ([]string, error) {
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func (u *LogService) PageLoginLog(req dto.SearchLgLogWithPage) (int64, interface{}, error) {
|
||||
func (u *LogService) PageLoginLog(c *gin.Context, req dto.SearchLgLogWithPage) (int64, interface{}, error) {
|
||||
total, ops, err := logRepo.PageLoginLog(
|
||||
req.Page,
|
||||
req.PageSize,
|
||||
@ -91,6 +94,7 @@ func (u *LogService) PageLoginLog(req dto.SearchLgLogWithPage) (int64, interface
|
||||
if err := copier.Copy(&item, &op); err != nil {
|
||||
return 0, nil, errors.WithMessage(constant.ErrStructTransform, err.Error())
|
||||
}
|
||||
item.Address, _ = geo.GetIPLocation(item.IP, common.GetLang(c))
|
||||
dtoOps = append(dtoOps, item)
|
||||
}
|
||||
return total, dtoOps, err
|
||||
|
@ -32,8 +32,8 @@ func GetIPLocation(ip, lang string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if lang == "en" {
|
||||
return geoLocation.Country.En + " " + geoLocation.Province.En, nil
|
||||
if lang == "zh" {
|
||||
return geoLocation.Country.Zh + " " + geoLocation.Province.Zh, nil
|
||||
}
|
||||
return geoLocation.Country.Zh + " " + geoLocation.Province.Zh, nil
|
||||
return geoLocation.Country.En + " " + geoLocation.Province.En, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user