mager: 合并11.3版本,包名和主线一样方便复制
This commit is contained in:
@@ -10,10 +10,9 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"nms_cxy/src/framework/constants/token"
|
||||
tokenUtils "nms_cxy/src/framework/utils/token"
|
||||
"nms_cxy/src/framework/vo"
|
||||
|
||||
"be.ems/src/framework/constants/token"
|
||||
tokenUtils "be.ems/src/framework/utils/token"
|
||||
"be.ems/src/framework/vo"
|
||||
"github.com/gorilla/mux"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package vo
|
||||
|
||||
import (
|
||||
"nms_cxy/lib/dborm"
|
||||
"be.ems/lib/dborm"
|
||||
)
|
||||
|
||||
// LoginUser 登录用户身份权限信息对象
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dborm
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
@@ -85,11 +86,16 @@ func Close() {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取默认数据源
|
||||
// default gorm DB
|
||||
func DefaultDB() *gorm.DB {
|
||||
return dbgEngine
|
||||
}
|
||||
|
||||
// get sql DB
|
||||
func GCoreDB() (*sql.DB, error) {
|
||||
return dbgEngine.DB()
|
||||
}
|
||||
|
||||
// RawSQL 原生查询语句
|
||||
func RawSQL(sql string, parameters []any) ([]map[string]any, error) {
|
||||
// 数据源
|
||||
|
||||
@@ -10,12 +10,13 @@ import (
|
||||
|
||||
"strings"
|
||||
|
||||
"nms_cxy/lib/log"
|
||||
"nms_cxy/lib/oauth"
|
||||
"nms_cxy/src/modules/system/model"
|
||||
"be.ems/lib/log"
|
||||
"be.ems/lib/oauth"
|
||||
"be.ems/src/modules/system/model"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/core"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -124,6 +125,14 @@ func XormConnectDatabase(dbType, dbUser, dbPassword, dbHost, dbPort, dbName stri
|
||||
return xEngine, nil
|
||||
}
|
||||
|
||||
func XCoreDB() *core.DB {
|
||||
return xEngine.DB()
|
||||
}
|
||||
|
||||
func XEngDB() *xorm.Engine {
|
||||
return xEngine
|
||||
}
|
||||
|
||||
func ConstructInsertSQL(tableName string, insertData interface{}) (string, []string) {
|
||||
log.Debug("ConstructInsertSQL processing... ")
|
||||
log.Debug("Request insertData:", insertData)
|
||||
@@ -419,68 +428,6 @@ func XormParseResult(body []byte) ([]NeInfo, error) {
|
||||
return neInfo, nil
|
||||
}
|
||||
|
||||
type ParamConfig struct {
|
||||
// Id int `json:"id" xorm:"pk 'id' autoincr"`
|
||||
NeType string `json:"neType"`
|
||||
NeId string `json:"neId"`
|
||||
TopTag string `json:"topTag"`
|
||||
TopDisplay string `json:"topDisplay"`
|
||||
ParamJson string `json:"paramJson"`
|
||||
}
|
||||
|
||||
func XormInsertParamConfig(mapJson *map[string]interface{}) (int64, error) {
|
||||
var affected, a int64
|
||||
var err error
|
||||
paramConfig := new(ParamConfig)
|
||||
for n, d := range *mapJson {
|
||||
if d == nil {
|
||||
break
|
||||
}
|
||||
log.Debugf("n: %s", n)
|
||||
|
||||
for t, p := range d.(map[string]interface{}) {
|
||||
if p == nil {
|
||||
break
|
||||
}
|
||||
log.Debug("t:", t)
|
||||
log.Debug("p:", p)
|
||||
for k, v := range p.(map[string]interface{}) {
|
||||
log.Debug("k, v: ", k, v)
|
||||
if k == "display" {
|
||||
paramConfig.TopDisplay = fmt.Sprintf("%v", v)
|
||||
|
||||
} else {
|
||||
pc, _ := json.Marshal(v)
|
||||
paramConfig.ParamJson = fmt.Sprintf("{\"%v\":%v}", k, string(pc))
|
||||
}
|
||||
}
|
||||
|
||||
paramConfig.NeType = strings.ToUpper(n)
|
||||
paramConfig.NeId = ""
|
||||
paramConfig.TopTag = t
|
||||
// paramConfig.TopDisplay = p["display"]
|
||||
// paramConfig.ParamJson = p.(string)
|
||||
|
||||
log.Debug("paramConfig:", paramConfig)
|
||||
|
||||
xSession := xEngine.NewSession()
|
||||
defer xSession.Close()
|
||||
_, err = xSession.Table("param_config").Where("ne_type = ? and top_tag = ?", paramConfig.NeType, paramConfig.TopTag).Delete()
|
||||
if err != nil {
|
||||
log.Error("Failed to insert param_config:", err)
|
||||
}
|
||||
a, err = xSession.Insert(paramConfig)
|
||||
if err != nil {
|
||||
log.Error("Failed to insert param_config:", err)
|
||||
}
|
||||
affected += a
|
||||
xSession.Commit()
|
||||
}
|
||||
}
|
||||
|
||||
return affected, err
|
||||
}
|
||||
|
||||
func ConstructUpdateSQLArray(tableName string, updateData interface{}, whereCondition string) (string, []string) {
|
||||
log.Debug("ConstructUpdateSQL processing... ")
|
||||
log.Debug("Request updateData:", updateData)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"math"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -29,6 +30,9 @@ func CalcExpr(expr string, paramValues map[string]any) (float64, error) {
|
||||
|
||||
// expression to evaluate
|
||||
result, err := evalExpr(expr)
|
||||
if math.IsNaN(result) {
|
||||
return 0.0, err
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
@@ -87,6 +91,10 @@ func evalNode(node ast.Node) (float64, error) {
|
||||
case token.MUL:
|
||||
result = left * right
|
||||
case token.QUO:
|
||||
if right == 0 {
|
||||
return math.NaN(), fmt.Errorf("divisor cannot be zero")
|
||||
}
|
||||
|
||||
result = left / right
|
||||
}
|
||||
case *ast.BasicLit:
|
||||
|
||||
@@ -6,8 +6,12 @@ package file
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
)
|
||||
|
||||
type FileInfo struct {
|
||||
@@ -16,7 +20,7 @@ type FileInfo struct {
|
||||
LinkCount int64 `json:"linkCount"` // 硬链接数目
|
||||
Owner string `json:"owner"` // 所属用户
|
||||
Group string `json:"group"` // 所属组
|
||||
Size int64 `json:"size"` // 文件的大小
|
||||
Size string `json:"size"` // 文件的大小
|
||||
ModifiedTime int64 `json:"modifiedTime"` // 最后修改时间,单位为秒
|
||||
FileName string `json:"fileName"` // 文件的名称
|
||||
}
|
||||
@@ -42,13 +46,26 @@ func GetFileInfo(dir, suffix string) ([]FileInfo, error) {
|
||||
|
||||
// check if match suffix
|
||||
if (suffix != "" && filepath.Ext(path) == suffix) || suffix == "" {
|
||||
stat, ok := info.Sys().(*syscall.Stat_t)
|
||||
if !ok {
|
||||
return fmt.Errorf("not a syscall.Stat_t")
|
||||
}
|
||||
userInfo, err := user.LookupId(fmt.Sprint(stat.Uid))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupInfo, err := user.LookupGroupId(fmt.Sprint(stat.Gid))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
humanReadableSize := humanize.Bytes(uint64(info.Size()))
|
||||
fileInfo := FileInfo{
|
||||
FileType: fileType,
|
||||
FileMode: info.Mode().String(),
|
||||
LinkCount: int64(info.Sys().(*syscall.Stat_t).Nlink),
|
||||
Owner: fmt.Sprintf("%d", info.Sys().(*syscall.Stat_t).Uid),
|
||||
Group: fmt.Sprintf("%d", info.Sys().(*syscall.Stat_t).Gid),
|
||||
Size: info.Size(),
|
||||
Owner: userInfo.Username,
|
||||
Group: groupInfo.Name,
|
||||
Size: strings.ToUpper(humanReadableSize),
|
||||
ModifiedTime: info.ModTime().Unix(),
|
||||
FileName: info.Name(),
|
||||
}
|
||||
|
||||
@@ -9,14 +9,15 @@ import (
|
||||
)
|
||||
|
||||
type FileInfo struct {
|
||||
FileType string `json:"fileType"` // 文件类型
|
||||
FileMode string `json:"fileMode"` // 文件的权限
|
||||
LinkCount int64 `json:"linkCount"` // 硬链接数目
|
||||
Owner string `json:"owner"` // 所属用户
|
||||
Group string `json:"group"` // 所属组
|
||||
Size int64 `json:"size"` // 文件的大小
|
||||
ModifiedTime int64 `json:"modifiedTime"` // 最后修改时间,单位为秒
|
||||
FileName string `json:"fileName"` // 文件的名称
|
||||
FileType string `json:"fileType"` // file type: file/directory
|
||||
FileMode string `json:"fileMode"` // file mode
|
||||
LinkCount int64 `json:"linkCount"` // link count
|
||||
Owner string `json:"owner"` // owner
|
||||
Group string `json:"group"` // group
|
||||
Size int64 `json:"size"` // size: xx byte
|
||||
ModifiedTime int64 `json:"modifiedTime"` // last modified time:seconds
|
||||
FilePath string `json:"filePath"` // file path
|
||||
FileName string `json:"fileName"` // file name
|
||||
}
|
||||
|
||||
func GetFileInfo(dir, suffix string) ([]FileInfo, error) {
|
||||
@@ -44,10 +45,11 @@ func GetFileInfo(dir, suffix string) ([]FileInfo, error) {
|
||||
FileType: fileType,
|
||||
FileMode: info.Mode().String(),
|
||||
LinkCount: 0,
|
||||
Owner: "N/A",
|
||||
Group: "N/A",
|
||||
Owner: "-",
|
||||
Group: "-",
|
||||
Size: info.Size(),
|
||||
ModifiedTime: info.ModTime().Unix(),
|
||||
FilePath: dir,
|
||||
FileName: info.Name(),
|
||||
}
|
||||
files = append(files, fileInfo)
|
||||
|
||||
@@ -4,10 +4,9 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"nms_cxy/lib/log"
|
||||
"nms_cxy/lib/services"
|
||||
tokenConst "nms_cxy/src/framework/constants/token"
|
||||
|
||||
"be.ems/lib/log"
|
||||
"be.ems/lib/services"
|
||||
tokenConst "be.ems/src/framework/constants/token"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"nms_cxy/lib/core/ctx"
|
||||
"nms_cxy/lib/log"
|
||||
"nms_cxy/src/framework/datasource"
|
||||
"nms_cxy/src/framework/utils/date"
|
||||
"be.ems/lib/core/ctx"
|
||||
"be.ems/lib/log"
|
||||
"be.ems/src/framework/datasource"
|
||||
"be.ems/src/framework/utils/date"
|
||||
)
|
||||
|
||||
// LogMML mml操作日志搜集
|
||||
|
||||
@@ -11,13 +11,13 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"nms_cxy/lib/core/ctx"
|
||||
"nms_cxy/src/framework/constants/common"
|
||||
"nms_cxy/src/framework/middleware/collectlogs"
|
||||
"nms_cxy/src/framework/utils/ip2region"
|
||||
"nms_cxy/src/framework/utils/parse"
|
||||
"nms_cxy/src/modules/system/model"
|
||||
"nms_cxy/src/modules/system/service"
|
||||
"be.ems/lib/core/ctx"
|
||||
"be.ems/src/framework/constants/common"
|
||||
"be.ems/src/framework/middleware/collectlogs"
|
||||
"be.ems/src/framework/utils/ip2region"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/modules/system/model"
|
||||
"be.ems/src/modules/system/service"
|
||||
)
|
||||
|
||||
// 敏感属性字段进行掩码
|
||||
|
||||
@@ -11,12 +11,11 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"nms_cxy/lib/dborm"
|
||||
"nms_cxy/lib/global"
|
||||
"nms_cxy/lib/log"
|
||||
"nms_cxy/lib/run"
|
||||
tokenConst "nms_cxy/src/framework/constants/token"
|
||||
|
||||
"be.ems/lib/dborm"
|
||||
"be.ems/lib/global"
|
||||
"be.ems/lib/log"
|
||||
"be.ems/lib/run"
|
||||
tokenConst "be.ems/src/framework/constants/token"
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
@@ -47,6 +46,7 @@ type MmlVar struct {
|
||||
Authorization string `josn:"authorization"`
|
||||
HttpUri string `json:"httpUri"`
|
||||
UserAgent string `json:"userAgent"`
|
||||
TagNE string `json:"tagNE"`
|
||||
}
|
||||
|
||||
// func init() {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"nms_cxy/lib/log"
|
||||
"be.ems/lib/log"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
@@ -5,24 +5,24 @@ import (
|
||||
|
||||
// "log"
|
||||
|
||||
"nms_cxy/features/aaaa"
|
||||
"nms_cxy/features/cdr"
|
||||
"nms_cxy/features/cm"
|
||||
"nms_cxy/features/dbrest"
|
||||
"nms_cxy/features/event"
|
||||
"nms_cxy/features/file"
|
||||
"nms_cxy/features/fm"
|
||||
"nms_cxy/features/lm"
|
||||
"nms_cxy/features/mml"
|
||||
"nms_cxy/features/pm"
|
||||
"nms_cxy/features/security"
|
||||
"nms_cxy/features/sm"
|
||||
"nms_cxy/features/state"
|
||||
"nms_cxy/features/trace"
|
||||
"nms_cxy/features/ue"
|
||||
"nms_cxy/lib/midware"
|
||||
"nms_cxy/lib/services"
|
||||
"nms_cxy/src/framework/middleware/collectlogs"
|
||||
"be.ems/features/aaaa"
|
||||
"be.ems/features/cdr"
|
||||
"be.ems/features/cm"
|
||||
"be.ems/features/dbrest"
|
||||
"be.ems/features/event"
|
||||
"be.ems/features/file"
|
||||
"be.ems/features/fm"
|
||||
"be.ems/features/lm"
|
||||
"be.ems/features/mml"
|
||||
"be.ems/features/pm"
|
||||
"be.ems/features/security"
|
||||
"be.ems/features/sm"
|
||||
"be.ems/features/state"
|
||||
"be.ems/features/trace"
|
||||
"be.ems/features/ue"
|
||||
"be.ems/lib/midware"
|
||||
"be.ems/lib/services"
|
||||
"be.ems/src/framework/middleware/collectlogs"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
@@ -207,13 +207,6 @@ func init() {
|
||||
Register("PUT", cm.CustomUriSoftwareNE, cm.ActiveSoftwareToNF, nil)
|
||||
Register("PATCH", cm.CustomUriSoftwareNE, cm.RollBackSoftwareToNF, nil)
|
||||
|
||||
// License management
|
||||
Register("POST", cm.UriLicense, cm.UploadLicenseFileData, midware.LogOperate(collectlogs.OptionNew("License", collectlogs.BUSINESS_TYPE_INSERT)))
|
||||
Register("POST", cm.UriLicenseExt, cm.UploadLicenseFileData, midware.LogOperate(collectlogs.OptionNew("License", collectlogs.BUSINESS_TYPE_INSERT)))
|
||||
|
||||
Register("POST", cm.CustomUriLicense, cm.UploadLicenseFileData, nil)
|
||||
Register("POST", cm.CustomUriLicenseExt, cm.UploadLicenseFileData, nil)
|
||||
|
||||
// Trace management 跟踪任务
|
||||
Register("POST", trace.UriTraceTask, trace.PostTraceTaskToNF, midware.LogOperate(collectlogs.OptionNew("Trace Task", collectlogs.BUSINESS_TYPE_INSERT)))
|
||||
Register("PUT", trace.UriTraceTask, trace.PutTraceTaskToNF, midware.LogOperate(collectlogs.OptionNew("Trace Task", collectlogs.BUSINESS_TYPE_UPDATE)))
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"bytes"
|
||||
"os/exec"
|
||||
|
||||
"nms_cxy/lib/log"
|
||||
"be.ems/lib/log"
|
||||
)
|
||||
|
||||
func ExecCmd(command, path string) ([]byte, error) {
|
||||
|
||||
@@ -6,7 +6,7 @@ package run
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
"nms_cxy/lib/log"
|
||||
"be.ems/lib/log"
|
||||
)
|
||||
|
||||
func ExecCmd(command, path string) ([]byte, error) {
|
||||
|
||||
@@ -6,7 +6,7 @@ package run
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
"nms_cxy/lib/log"
|
||||
"be.ems/lib/log"
|
||||
)
|
||||
|
||||
func ExecCmd(command, path string) ([]byte, error) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"nms_cxy/lib/log"
|
||||
"be.ems/lib/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -6,7 +6,7 @@ const (
|
||||
)
|
||||
|
||||
func ErrResp(msg string) map[string]any {
|
||||
return map[string]any{"code": CODE_FAIL, "message": msg}
|
||||
return map[string]any{"code": CODE_FAIL, "msg": msg}
|
||||
}
|
||||
|
||||
func DataResp(data any) map[string]any {
|
||||
@@ -14,7 +14,7 @@ func DataResp(data any) map[string]any {
|
||||
}
|
||||
|
||||
func SuccMessageResp() map[string]any {
|
||||
return map[string]any{"code": CODE_SUCC, "message": "success"}
|
||||
return map[string]any{"code": CODE_SUCC, "msg": "success"}
|
||||
}
|
||||
|
||||
func TotalResp(total int64) map[string]any {
|
||||
|
||||
@@ -16,12 +16,11 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"nms_cxy/lib/dborm"
|
||||
"nms_cxy/lib/global"
|
||||
"nms_cxy/lib/log"
|
||||
"nms_cxy/lib/oauth"
|
||||
"nms_cxy/omc/config"
|
||||
|
||||
"be.ems/lib/dborm"
|
||||
"be.ems/lib/global"
|
||||
"be.ems/lib/log"
|
||||
"be.ems/lib/oauth"
|
||||
"be.ems/restagent/config"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"nms_cxy/lib/log"
|
||||
"nms_cxy/lib/oauth"
|
||||
"nms_cxy/omc/config"
|
||||
"be.ems/lib/log"
|
||||
"be.ems/lib/oauth"
|
||||
"be.ems/restagent/config"
|
||||
)
|
||||
|
||||
// SessionMgr session manager
|
||||
|
||||
Reference in New Issue
Block a user