merge: 合并代码20240531
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
sysMenuService "be.ems/features/sys_menu/service"
|
||||
sysRoleService "be.ems/features/sys_role/service"
|
||||
"be.ems/lib/core/cache"
|
||||
"be.ems/lib/core/vo"
|
||||
"be.ems/lib/dborm"
|
||||
srcConfig "be.ems/src/framework/config"
|
||||
)
|
||||
|
||||
// 登录缓存用户信息
|
||||
func CacheLoginUser(user *dborm.User) {
|
||||
// 过期时间
|
||||
expiresStr, err := dborm.XormGetConfigValue("Security", "sessionExpires")
|
||||
if err != nil {
|
||||
expiresStr = "18000"
|
||||
}
|
||||
expiresValue, _ := strconv.Atoi(expiresStr)
|
||||
expireTime := time.Duration(expiresValue) * time.Second
|
||||
|
||||
nowTime := time.Now().UnixMilli()
|
||||
|
||||
// 登录用户
|
||||
loginUser := vo.LoginUser{
|
||||
UserID: fmt.Sprint(user.Id),
|
||||
UserName: user.Name,
|
||||
ExpireTime: nowTime + expireTime.Milliseconds(),
|
||||
LoginTime: nowTime,
|
||||
User: *user,
|
||||
}
|
||||
|
||||
// 是否管理员
|
||||
if srcConfig.IsAdmin(loginUser.UserID) {
|
||||
loginUser.Permissions = []string{"*:*:*"}
|
||||
} else {
|
||||
// 获取权限标识
|
||||
loginUser.Permissions = sysMenuService.NewRepoSysMenu.SelectMenuPermsByUserId(loginUser.UserID)
|
||||
// 获取角色信息
|
||||
loginUser.User.Roles = sysRoleService.NewRepoSysRole.SelectRoleListByUserId(loginUser.UserID)
|
||||
}
|
||||
|
||||
// 缓存时间
|
||||
cache.SetLocalTTL(user.AccountId, loginUser, time.Duration(expireTime))
|
||||
}
|
||||
|
||||
// 清除缓存用户信息
|
||||
func ClearLoginUser(accountId string) {
|
||||
cache.DeleteLocalTTL(accountId)
|
||||
}
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
|
||||
"strings"
|
||||
|
||||
"be.ems/features/sys_role/model"
|
||||
"be.ems/lib/log"
|
||||
"be.ems/lib/oauth"
|
||||
"be.ems/src/modules/system/model"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"xorm.io/xorm"
|
||||
@@ -1402,11 +1402,11 @@ type MeasureThreshold struct {
|
||||
type NeSoftware struct {
|
||||
Id int `json:"id" xorm:"pk 'id' autoincr"`
|
||||
NeType string `json:"neType" xorm:"ne_type"`
|
||||
FileName string `json:"neName" xorm:"file_name"`
|
||||
Path string `json:"path"`
|
||||
Version string `json:"version"`
|
||||
Md5Sum string `json:"md5Sum" xorm:"md5_sum"`
|
||||
Comment string `json:"comment"`
|
||||
FileName string `json:"fileName" xorm:"name"`
|
||||
Path string `json:"path" xorm:"path"`
|
||||
Version string `json:"version" `
|
||||
Md5Sum string `json:"md5Sum" xorm:"-"`
|
||||
Comment string `json:"comment" xorm:"description"`
|
||||
// Status string `json:"status"`
|
||||
UpdateTime string `json:"createTime" xorm:"-" `
|
||||
}
|
||||
@@ -1415,18 +1415,18 @@ type NeVersion struct {
|
||||
Id int `json:"id" xorm:"pk 'id' autoincr"`
|
||||
NeType string `json:"neType" xorm:"ne_type"`
|
||||
NeId string `json:"neId" xorm:"ne_id"`
|
||||
Version string `json:"version"`
|
||||
FilePath string `json:"filePath" xorm:"file_path"`
|
||||
Version string `json:"version" `
|
||||
FilePath string `json:"filePath" xorm:"path"`
|
||||
NewVersion string `json:"newVersion" xorm:"new_version"`
|
||||
NewFile string `json:"newFile" xorm:"new_file"`
|
||||
NewFile string `json:"newFile" xorm:"new_path"`
|
||||
PreVersion string `json:"preVersion" xorm:"pre_version"`
|
||||
PreFile string `json:"preFile" xorm:"pre_file"`
|
||||
Status string `json:"status"`
|
||||
PreFile string `json:"preFile" xorm:"pre_path"`
|
||||
Status string `json:"status" xorm:"status"`
|
||||
UpdateTime string `json:"createTime" xorm:"-" `
|
||||
}
|
||||
|
||||
func XormGetDataBySQL(sql string) (*[]map[string]string, error) {
|
||||
//log.Debug("XormGetDataBySQL processing... ")
|
||||
log.Debug("XormGetDataBySQL processing... ")
|
||||
|
||||
rows := make([]map[string]string, 0)
|
||||
rows, err := DbClient.XEngine.QueryString(sql)
|
||||
@@ -1708,25 +1708,26 @@ func IsPermissionAllowed(token, method, module, dbname, tbname, pack string) (bo
|
||||
type NeLicense struct {
|
||||
NeType string `json:"neType" xorm:"ne_type"`
|
||||
NeID string `json:"neID" xorm:"ne_id"`
|
||||
SerialNo string `json:"serialNo" xorm:"serial_no"`
|
||||
Capcity int `json:"capcity" xorm:"capcity"`
|
||||
Used int `json:"used" xorm:"used"`
|
||||
FeatureEnabled string `json:"featureEnabled" xorm:"feature_enabled"`
|
||||
ExpirationDate string `json:"expirationDate" xorm:"expiration_date"`
|
||||
SerialNo string `json:"serialNo" xorm:"serial_num"`
|
||||
Capcity int `json:"capcity" xorm:"-"`
|
||||
Used int `json:"used" xorm:"-"`
|
||||
FeatureEnabled string `json:"featureEnabled" xorm:"-"`
|
||||
ExpirationDate string `json:"expirationDate" xorm:"expiry_date"`
|
||||
Status string `json:"status" xorm:"status"`
|
||||
Path string `json:"path" xorm:"path"`
|
||||
FileName string `json:"file_name" xorm:"file_name"`
|
||||
Comment string `json:"comment" xorm:"comment"`
|
||||
Path string `json:"path" xorm:"license_path"`
|
||||
FileName string `json:"file_name" xorm:"-"`
|
||||
Comment string `json:"comment" xorm:"remark"`
|
||||
CreatedAt string `json:"createdAt" xorm:"-"`
|
||||
UpdatedAt string `json:"updatedAt" xorm:"-"`
|
||||
DeletedAt string `json:"deletedAt" xorm:"-"`
|
||||
}
|
||||
|
||||
func XormAdjustmentNeLicense(neType, neID string, value int) (int64, error) {
|
||||
return 1, nil
|
||||
//neLicense := NeLicense{NeType: neType, NeID: neID, Capability: value}
|
||||
// session.LogoutTime.Valid = true
|
||||
// session.LogoutTime.Time = time.Now()
|
||||
res, err := xEngine.Exec("update ne_license set capcity=capcity+? where IFNULL(ne_type, '')=? and IFNULL(ne_id, '')=?", value, neType, neID)
|
||||
// res, err := xEngine.Exec("update ne_license set capcity=capcity+? where IFNULL(ne_type, '')=? and IFNULL(ne_id, '')=?", value, neType, neID)
|
||||
// defer xSession.Close()
|
||||
|
||||
//affected, err := xSession.Table("ne_license").Where("ne_type=? and ne_id=?", neType, neID).Update(&neLicense)
|
||||
@@ -1734,25 +1735,26 @@ func XormAdjustmentNeLicense(neType, neID string, value int) (int64, error) {
|
||||
// //affected, err := xSession.Table("ne_license").SQL("ne_tye=? and ne_id=?", neType, neID).Update(session)
|
||||
// err := xSession.SQL("update ne_license set capability=capability+? where ne_type=? and ne_id=?", value, neType, neID)
|
||||
//xSession.Commit()
|
||||
affected, err := res.RowsAffected()
|
||||
return affected, err
|
||||
// affected, err := res.RowsAffected()
|
||||
// return affected, err
|
||||
}
|
||||
|
||||
func XormUpdateNeLicense(neType, neID string, capcity int) (int64, error) {
|
||||
var err error
|
||||
var res sql.Result
|
||||
if neType != "" && neID != "" {
|
||||
res, err = xEngine.Exec("update ne_license set capcity=? where ne_type=? and ne_id=?", capcity, neType, neID)
|
||||
} else if neType != "" && neID == "" {
|
||||
res, err = xEngine.Exec("update ne_license set capcity=? where ne_type=?", capcity, neType)
|
||||
} else if neType == "" && neID != "" {
|
||||
res, err = xEngine.Exec("update ne_license set capcity=? where ne_id=?", capcity, neID)
|
||||
} else {
|
||||
res, err = xEngine.Exec("update ne_license set capcity=?", capcity)
|
||||
}
|
||||
return 1, nil
|
||||
// var err error
|
||||
// var res sql.Result
|
||||
// if neType != "" && neID != "" {
|
||||
// res, err = xEngine.Exec("update ne_license set capcity=? where ne_type=? and ne_id=?", capcity, neType, neID)
|
||||
// } else if neType != "" && neID == "" {
|
||||
// res, err = xEngine.Exec("update ne_license set capcity=? where ne_type=?", capcity, neType)
|
||||
// } else if neType == "" && neID != "" {
|
||||
// res, err = xEngine.Exec("update ne_license set capcity=? where ne_id=?", capcity, neID)
|
||||
// } else {
|
||||
// res, err = xEngine.Exec("update ne_license set capcity=?", capcity)
|
||||
// }
|
||||
|
||||
affected, err := res.RowsAffected()
|
||||
return affected, err
|
||||
// affected, err := res.RowsAffected()
|
||||
// return affected, err
|
||||
}
|
||||
|
||||
type NorthboundCm struct {
|
||||
@@ -1777,21 +1779,21 @@ func XormGetNorthboundCm(neType string, cmResults *[]NorthboundCm) error {
|
||||
log.Info("XormGetNorthboundCm processing... ")
|
||||
|
||||
cmResult := new(NorthboundCm)
|
||||
rows, err := xEngine.Table("northbound_cm").
|
||||
rows, err := xEngine.Table("nbi_cm").
|
||||
Distinct("object_type").
|
||||
Where("`ne_type` = ?", neType).
|
||||
Desc("timestamp").
|
||||
Cols("*").
|
||||
Rows(cmResult)
|
||||
if err != nil {
|
||||
log.Error("Failed to get table northbound_cm:", err)
|
||||
log.Error("Failed to get table nbi_cm:", err)
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
err := rows.Scan(cmResult)
|
||||
if err != nil {
|
||||
log.Error("Failed to get table northbound_cm:", err)
|
||||
log.Error("Failed to get table nbi_cm:", err)
|
||||
return err
|
||||
}
|
||||
*cmResults = append(*cmResults, *cmResult)
|
||||
@@ -1803,14 +1805,14 @@ func XormGetNorthboundCmLatestObject(neType, neID, objectType string) (*Northbou
|
||||
log.Info("XormGetNorthboundCmLatestObject processing... ")
|
||||
|
||||
cmResult := new(NorthboundCm)
|
||||
_, err := xEngine.Table("northbound_cm").
|
||||
_, err := xEngine.Table("nbi_cm").
|
||||
Where("`ne_type`=? and `ne_id`=? and `object_type`=?", neType, neID, objectType).
|
||||
Desc("timestamp").
|
||||
Cols("*").
|
||||
Limit(1).
|
||||
Get(cmResult)
|
||||
if err != nil {
|
||||
log.Error("Failed to get table northbound_cm:", err)
|
||||
log.Error("Failed to get table nbi_cm:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -696,3 +696,33 @@ func IsRpmOrDebPackage(filePath string) int {
|
||||
|
||||
return fileType
|
||||
}
|
||||
|
||||
func RecurseStructToMap(obj any) map[string]any {
|
||||
out := make(map[string]any)
|
||||
v := reflect.ValueOf(obj)
|
||||
if v.Kind() == reflect.Ptr {
|
||||
v = v.Elem()
|
||||
}
|
||||
|
||||
// 递归函数,用于处理嵌套结构体
|
||||
var recurse func(reflect.Value) any
|
||||
recurse = func(value reflect.Value) any {
|
||||
if value.Kind() == reflect.Struct {
|
||||
nestedOut := make(map[string]any)
|
||||
for i := 0; i < value.NumField(); i++ {
|
||||
nestedOut[value.Type().Field(i).Name] = recurse(value.Field(i))
|
||||
}
|
||||
return nestedOut
|
||||
} else if value.Kind() == reflect.Ptr {
|
||||
return recurse(value.Elem())
|
||||
}
|
||||
return value.Interface()
|
||||
}
|
||||
|
||||
t := v.Type()
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
f := v.Field(i)
|
||||
out[t.Field(i).Name] = recurse(f)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"be.ems/lib/services"
|
||||
)
|
||||
|
||||
// 已禁用
|
||||
// 登录策略限制登录时间和访问ip范围
|
||||
func ArrowIPAddr(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
tokenUtils "be.ems/src/framework/utils/token"
|
||||
)
|
||||
|
||||
// 已禁用由Gin部分接管
|
||||
// Authorize 用户身份授权认证校验
|
||||
//
|
||||
// 只需含有其中角色 "hasRoles": {"xxx"},
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 已禁用由Gin部分接管
|
||||
// Cors 跨域
|
||||
func Cors(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/lib/core/utils/ctx"
|
||||
"be.ems/lib/core/utils/parse"
|
||||
"be.ems/lib/dborm"
|
||||
"be.ems/src/framework/constants/common"
|
||||
"be.ems/src/framework/middleware/collectlogs"
|
||||
"be.ems/src/framework/utils/ip2region"
|
||||
@@ -47,13 +47,7 @@ func LogOperate(options collectlogs.Options) func(http.Handler) http.Handler {
|
||||
funcName = funcName[lastDotIndex+1:]
|
||||
|
||||
// 用户名
|
||||
username := "-"
|
||||
accessToken := r.Header.Get("AccessToken")
|
||||
if accessToken != "" {
|
||||
// 验证令牌 == 这里直接查数据库session
|
||||
se, _ := dborm.XormUpdateSessionShakeTime(accessToken)
|
||||
username = se.AccountId
|
||||
}
|
||||
username := ctx.LoginUserToUserName(r)
|
||||
|
||||
// 解析ip地址
|
||||
ip := strings.Split(r.RemoteAddr, ":")[0]
|
||||
|
||||
@@ -13,21 +13,12 @@ import (
|
||||
"be.ems/features/fm"
|
||||
"be.ems/features/lm"
|
||||
"be.ems/features/mml"
|
||||
"be.ems/features/monitor/monitor"
|
||||
"be.ems/features/monitor/psnet"
|
||||
"be.ems/features/nbi"
|
||||
"be.ems/features/pm"
|
||||
"be.ems/features/security"
|
||||
"be.ems/features/sm"
|
||||
"be.ems/features/state"
|
||||
sysconfig "be.ems/features/sys_config"
|
||||
sysdictdata "be.ems/features/sys_dict_data"
|
||||
sysdicttype "be.ems/features/sys_dict_type"
|
||||
sysmenu "be.ems/features/sys_menu"
|
||||
sysrole "be.ems/features/sys_role"
|
||||
sysuser "be.ems/features/sys_user"
|
||||
"be.ems/features/trace"
|
||||
udmuser "be.ems/features/udm_user"
|
||||
"be.ems/features/ue"
|
||||
"be.ems/lib/midware"
|
||||
"be.ems/lib/services"
|
||||
@@ -233,16 +224,6 @@ func init() {
|
||||
Register("PUT", trace.CustomUriTraceTask, trace.PutTraceTaskToNF, nil)
|
||||
Register("DELETE", trace.CustomUriTraceTask, trace.DeleteTraceTaskToNF, nil)
|
||||
|
||||
// 网元发送执行 pcap抓包任务
|
||||
Register("POST", trace.UriTcpdumpTask, trace.TcpdumpNeTask, midware.LogOperate(collectlogs.OptionNew("Packet Capturing Task", collectlogs.BUSINESS_TYPE_INSERT)))
|
||||
Register("POST", trace.CustomUriTcpdumpTask, trace.TcpdumpNeTask, midware.LogOperate(collectlogs.OptionNew("Packet Capturing Task", collectlogs.BUSINESS_TYPE_INSERT)))
|
||||
// 网元发送执行 抓包下载pcap文件
|
||||
Register("POST", trace.UriTcpdumpPcapDownload, trace.TcpdumpPcapDownload, midware.LogOperate(collectlogs.OptionNew("Packet Capturing Task", collectlogs.BUSINESS_TYPE_EXPORT)))
|
||||
Register("POST", trace.CustomUriTcpdumpPcapDownload, trace.TcpdumpPcapDownload, midware.LogOperate(collectlogs.OptionNew("Packet Capturing Task", collectlogs.BUSINESS_TYPE_EXPORT)))
|
||||
// 网元发送执行UPF pcap抓包
|
||||
Register("POST", trace.UriTcpdumpNeUPFTask, trace.TcpdumpNeUPFTask, midware.LogOperate(collectlogs.OptionNew("Packet Capturing Task", collectlogs.BUSINESS_TYPE_INSERT)))
|
||||
Register("POST", trace.CustomUriTcpdumpNeUPFTask, trace.TcpdumpNeUPFTask, midware.LogOperate(collectlogs.OptionNew("Packet Capturing Task", collectlogs.BUSINESS_TYPE_INSERT)))
|
||||
|
||||
// file management
|
||||
Register("POST", file.UriFile, file.UploadFile, midware.LogOperate(collectlogs.OptionNew("File", collectlogs.BUSINESS_TYPE_INSERT)))
|
||||
Register("GET", file.UriFile, file.DownloadFile, midware.LogOperate(collectlogs.OptionNew("File", collectlogs.BUSINESS_TYPE_OTHER)))
|
||||
@@ -300,23 +281,17 @@ func init() {
|
||||
Register("GET", ue.UriNSSFSubscriptions, ue.GetSubscriptionsFromNSSF, nil)
|
||||
Register("GET", ue.CustomUriNSSFSubscriptions, ue.GetSubscriptionsFromNSSF, nil)
|
||||
|
||||
Register("POST", cdr.UriCDREvent, cdr.PostCDREventFromNF, nil)
|
||||
Register("POST", cdr.CustomUriCDREvent, cdr.PostCDREventFromNF, nil)
|
||||
// ims cdr event
|
||||
Register("POST", cdr.UriIMSCDREvent, cdr.PostCDREventFromIMS, nil)
|
||||
Register("POST", cdr.CustomUriIMSCDREvent, cdr.PostCDREventFromIMS, nil)
|
||||
|
||||
// UE event
|
||||
// smf cdr event
|
||||
Register("POST", cdr.UriSMFCDREvent, cdr.PostCDREventFromSMF, nil)
|
||||
Register("POST", cdr.CustomUriSMFCDREvent, cdr.PostCDREventFromSMF, nil)
|
||||
|
||||
// UE event AMF上报的UE事件, 无前缀给到Gin处理
|
||||
//Register("POST", event.UriUEEvent, event.PostUEEventFromAMF, nil)
|
||||
|
||||
// 进程网络
|
||||
Register("GET", psnet.UriWs, psnet.ProcessWs, nil)
|
||||
Register("POST", psnet.UriStop, psnet.StopProcess, nil)
|
||||
Register("POST", psnet.UriPing, psnet.Ping, nil)
|
||||
|
||||
// 主机CPU内存监控
|
||||
Register("POST", monitor.UriLoad, monitor.LoadMonitor, nil)
|
||||
Register("GET", monitor.UriNetOpt, monitor.Netoptions, nil)
|
||||
Register("GET", monitor.UriIPAddr, monitor.IPAddr, nil)
|
||||
Register("GET", monitor.UriIoOpt, monitor.Iooptions, nil)
|
||||
|
||||
// 文件资源
|
||||
Register("GET", file.UriDiskList, file.DiskList, nil)
|
||||
Register("POST", file.UriListFiles, file.ListFiles, nil)
|
||||
@@ -337,56 +312,6 @@ func init() {
|
||||
Register("POST", lm.ExtBackupDataUri, lm.ExtDatabaseBackupData, nil)
|
||||
Register("POST", lm.CustomExtBackupDataUri, lm.ExtDatabaseBackupData, nil)
|
||||
|
||||
// 系统登录
|
||||
Register("POST", security.UriLogin, security.LoginOMC, nil)
|
||||
Register("POST", security.CustomUriLogin, security.LoginOMC, nil)
|
||||
|
||||
// 获取验证码
|
||||
Register("GET", security.UriCaptchaImage, security.CaptchaImage, nil)
|
||||
Register("GET", security.CustomUriCaptchaImage, security.CaptchaImage, nil)
|
||||
|
||||
// 登录用户信息
|
||||
Register("GET", security.UriUserInfo, security.UserInfo, midware.Authorize(nil))
|
||||
Register("GET", security.CustomUriUserInfo, security.UserInfo, midware.Authorize(nil))
|
||||
|
||||
// 登录用户路由信息
|
||||
Register("GET", security.UriRouters, security.Routers, midware.Authorize(nil))
|
||||
Register("GET", security.CustomUriRouters, security.Routers, midware.Authorize(nil))
|
||||
|
||||
// 参数配置信息接口添加到路由
|
||||
for _, v := range sysconfig.Routers() {
|
||||
Register(v.Method, v.Pattern, v.Handler, v.Middleware)
|
||||
}
|
||||
|
||||
// 字典类型信息接口添加到路由
|
||||
for _, v := range sysdicttype.Routers() {
|
||||
Register(v.Method, v.Pattern, v.Handler, v.Middleware)
|
||||
}
|
||||
|
||||
// 字典类型对应的字典数据信息接口添加到路由
|
||||
for _, v := range sysdictdata.Routers() {
|
||||
Register(v.Method, v.Pattern, v.Handler, v.Middleware)
|
||||
}
|
||||
|
||||
// 菜单接口添加到路由
|
||||
for _, v := range sysmenu.Routers() {
|
||||
Register(v.Method, v.Pattern, v.Handler, v.Middleware)
|
||||
}
|
||||
|
||||
// 角色接口添加到路由
|
||||
for _, v := range sysrole.Routers() {
|
||||
Register(v.Method, v.Pattern, v.Handler, v.Middleware)
|
||||
}
|
||||
|
||||
// 用户接口添加到路由
|
||||
for _, v := range sysuser.Routers() {
|
||||
Register(v.Method, v.Pattern, v.Handler, v.Middleware)
|
||||
}
|
||||
|
||||
// UDM 用户信息接口添加到路由
|
||||
for _, v := range udmuser.Routers() {
|
||||
Register(v.Method, v.Pattern, v.Handler, v.Middleware)
|
||||
}
|
||||
}
|
||||
|
||||
// To resolv rest POST/PUT/DELETE/PATCH cross domain
|
||||
|
||||
Reference in New Issue
Block a user