From 269b578d77ca3651414fb9c229d0aedc1c49519d Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Fri, 12 Jan 2024 16:13:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A1=A5=E5=85=85=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- features/cm/exec_linux.go | 29 ++++++++++ features/cm/exec_windows.go | 30 +++++++++++ features/cm/ne.go | 35 ++++++++++-- features/cm/param.go | 10 ++-- features/cm/software.go | 24 +++++++-- features/fm/alarm.go | 16 +++--- features/mml/mml.go | 39 ++++++++++---- features/security/account.go | 101 +++++++++++++++++++++++++++++++++++ features/state/getstate.go | 13 ++--- features/ue/ue.go | 2 +- 10 files changed, 264 insertions(+), 35 deletions(-) diff --git a/features/cm/exec_linux.go b/features/cm/exec_linux.go index 3044649..088fd86 100644 --- a/features/cm/exec_linux.go +++ b/features/cm/exec_linux.go @@ -5,7 +5,9 @@ package cm import ( "bytes" + "context" "os/exec" + "time" "ems.agt/lib/log" ) @@ -64,3 +66,30 @@ func ExecOsCmd(command, os string) error { } return nil } + +func StartSSHCmdWithTimeout(duration int, sshHost, cmdStr string) error { + timeout := time.Duration(duration) * time.Second + ctx, cancel := context.WithTimeout(context.Background(), timeout) // 设置超时 + defer cancel() + cmd := exec.CommandContext(ctx, "ssh", sshHost, cmdStr) + var stdout, stderr bytes.Buffer + cmd.Stdout = &stdout + cmd.Stderr = &stderr + err := cmd.Start() + if err != nil { + return err + } + return nil +} + +func RunSSHCmd(sshHost, cmdStr string) error { + cmd := exec.Command("ssh", sshHost, cmdStr) + var stdout, stderr bytes.Buffer + cmd.Stdout = &stdout + cmd.Stderr = &stderr + err := cmd.Run() + if err != nil { + return err + } + return nil +} diff --git a/features/cm/exec_windows.go b/features/cm/exec_windows.go index fa15045..0c1d038 100644 --- a/features/cm/exec_windows.go +++ b/features/cm/exec_windows.go @@ -4,7 +4,10 @@ package cm import ( + "bytes" + "context" "os/exec" + "time" "ems.agt/lib/log" ) @@ -51,3 +54,30 @@ func ExecOsCmd(command, os string) error { } return nil } + +func StartSSHCmdWithTimeout(duration int, sshHost, cmdStr string) error { + timeout := time.Duration(duration) * time.Second + ctx, cancel := context.WithTimeout(context.Background(), timeout) // 设置超时 + defer cancel() + cmd := exec.CommandContext(ctx, "ssh", sshHost, cmdStr) + var stdout, stderr bytes.Buffer + cmd.Stdout = &stdout + cmd.Stderr = &stderr + err := cmd.Start() + if err != nil { + return err + } + return nil +} + +func RunSSHCmd(sshHost, cmdStr string) error { + cmd := exec.Command("ssh", sshHost, cmdStr) + var stdout, stderr bytes.Buffer + cmd.Stdout = &stdout + cmd.Stderr = &stderr + err := cmd.Run() + if err != nil { + return err + } + return nil +} diff --git a/features/cm/ne.go b/features/cm/ne.go index a92b935..458850f 100644 --- a/features/cm/ne.go +++ b/features/cm/ne.go @@ -15,6 +15,7 @@ import ( "ems.agt/lib/log" "ems.agt/lib/services" "ems.agt/restagent/config" + tokenConst "ems.agt/src/framework/constants/token" "github.com/go-resty/resty/v2" "github.com/gorilla/mux" @@ -22,6 +23,7 @@ import ( var ( UriParamOmcNeConfig = config.DefaultUriPrefix + "/systemManagement/v1/elementType/%s/objectType/config/omcNeConfig" + UriOmcNeConfig = config.DefaultUriPrefix + "/systemManagement/v1/elementType/omc/objectType/config/omcNeConfig" // NE CM export/import NeCmUri = config.DefaultUriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/cm" // NE info @@ -34,6 +36,7 @@ var ( UriNeInstance = config.DefaultUriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/instance/{action}" CustomUriParamOmcNeConfig = config.UriPrefix + "/systemManagement/v1/elementType/%s/objectType/config/omcNeConfig" + CustomUriOmcNeConfig = config.UriPrefix + "/systemManagement/v1/elementType/omc/objectType/config/omcNeConfig" CustomNeCmUri = config.UriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/cm" CustomUriNeInfo = config.UriPrefix + "/systemManagement/{apiVersion}/elementType/{elementTypeValue}/objectType/neInfo" CustomUriNeCmFile = config.UriPrefix + "/systemManagement/{apiVersion}/{neType}/neBackup/{fileName}" @@ -125,6 +128,7 @@ func PostNeInfo(w http.ResponseWriter, r *http.Request) { services.ResponseNotFound404UriNotExist(w, r) return } + neTypeUpper := strings.ToUpper(neType) syncFlag := services.GetUriParamString(r, "sync2ne", ",", false, false) body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen)) if err != nil { @@ -145,7 +149,7 @@ func PostNeInfo(w http.ResponseWriter, r *http.Request) { log.Debug("NE info:", neInfo) //if !config.GetYamlConfig().OMC.Chk2Ne { - if syncFlag == "false" { + if syncFlag == "false" || neTypeUpper == config.GetYamlConfig().OMC.NeType { neInfo.Status = NEStatusMaintain affected, err := dborm.XormInsertNeInfo(neInfo) if err != nil { @@ -231,6 +235,8 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) { services.ResponseNotFound404UriNotExist(w, r) return } + neTypeLower := strings.ToLower(neType) + neTypeUpper := strings.ToUpper(neType) syncFlag := services.GetUriParamString(r, "sync2ne", ",", false, false) body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen)) if err != nil { @@ -246,7 +252,7 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) { log.Debug("NE info:", neInfo) //if !config.GetYamlConfig().OMC.Chk2Ne { - if syncFlag == "false" { + if syncFlag == "false" || neTypeUpper == config.GetYamlConfig().OMC.NeType { neInfo.Status = NEStatusMaintain affected, err := dborm.XormUpdateNeInfo(neInfo) if err != nil { @@ -263,7 +269,7 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) { } else { hostUri := global.CombineHostUri(neInfo.Ip, neInfo.Port) //hostUri := fmt.Sprintf("http://%s:%v", neInfo.Ip, neInfo.Port) - apiUri := fmt.Sprintf(UriParamOmcNeConfig, strings.ToLower(neType)) + apiUri := fmt.Sprintf(UriParamOmcNeConfig, neTypeLower) requestURI2NF := fmt.Sprintf("%s%s", hostUri, apiUri) log.Debug("requestURI2NF:", requestURI2NF) @@ -279,6 +285,7 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) { body, _ = json.Marshal(omcNeConfig) response, err := client.R(). EnableTrace(). + SetHeaders(map[string]string{tokenConst.HEADER_KEY: r.Header.Get(tokenConst.HEADER_KEY)}). SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}). SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}). SetBody(body). @@ -316,6 +323,28 @@ func PutNeInfo(w http.ResponseWriter, r *http.Request) { } } +func PutOMCNeConfig(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + neType := vars["elementTypeValue"] + if neType == "" { + log.Error("elementTypeValue is empty") + services.ResponseNotFound404UriNotExist(w, r) + return + } + body, err := io.ReadAll(io.LimitReader(r.Body, global.RequestBodyMaxLen)) + if err != nil { + log.Error("Failed to io.ReadAll:", err) + services.ResponseNotFound404UriNotExist(w, r) + return + } + + neInfo := new(dborm.NeInfo) + _ = json.Unmarshal(body, neInfo) + neInfo.NeType = strings.ToUpper(neType) + + services.ResponseStatusOK204NoContent(w) +} + func DeleteNeInfo(w http.ResponseWriter, r *http.Request) { log.Debug("DeleteNeInfo processing... ") diff --git a/features/cm/param.go b/features/cm/param.go index 2a68a87..aa396f8 100644 --- a/features/cm/param.go +++ b/features/cm/param.go @@ -48,9 +48,9 @@ func GetParamConfigFromNF(w http.ResponseWriter, r *http.Request) { getNeInfoURI := restHostPort + getNeInfoPattern neId := services.GetUriParamString(r, "ne_id", ",", true, true) if neId == "" { - getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status='0'+and+ne_type='%s'", neType) + getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status+in+('0','3')+and+ne_type='%s'", neType) } else { - getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status='0'+and+ne_type='%v'+and+ne_id+in+%v", neType, neId) + getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status+in+('0','3')+and+ne_type='%v'+and+ne_id+in+%v", neType, neId) } log.Debug("getNeInfoURI:", getNeInfoURI) @@ -63,11 +63,11 @@ func GetParamConfigFromNF(w http.ResponseWriter, r *http.Request) { SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}). Get(getNeInfoURI) if err != nil { - log.Error("Get from database is failure!") - services.ResponseInternalServerError500NFConnectRefused(w) + log.Error("Failed to Get:", err) + services.ResponseInternalServerError500ProcessError(w, err) return } - log.Debug("NE info:", string(resp.Body())) + log.Trace("NE info:", string(resp.Body())) // var neList []dborm.NeInfo neList, _ := dborm.XormParseResult(resp.Body()) diff --git a/features/cm/software.go b/features/cm/software.go index 34bb73a..269e0d5 100644 --- a/features/cm/software.go +++ b/features/cm/software.go @@ -699,14 +699,32 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) { } } else if fileType == 2 { dpkgCmd := fmt.Sprintf("sudo dpkg -i --force-all '%s'", filePath) - cmd := exec.Command("ssh", sshHost, dpkgCmd) - out, err := cmd.CombinedOutput() - log.Debugf("Exec output: %v", string(out)) + err := RunSSHCmd(sshHost, dpkgCmd) if err != nil { log.Error("Faile to execute dpkg command:", err) services.ResponseInternalServerError500ProcessError(w, err) return } + // timeout := time.Duration(config.GetYamlConfig().OMC.CmdTimeout) * time.Second + // ctx, cancel := context.WithTimeout(context.Background(), timeout) // 设置超时 + // defer cancel() + // cmd := exec.CommandContext(ctx, "ssh", sshHost, dpkgCmd) + // var stdout, stderr bytes.Buffer + // cmd.Stdout = &stdout + // cmd.Stderr = &stderr + // err := cmd.Start() + // if err != nil { + // log.Error("Faile to execute dpkg command: %v, err: %s", err, stderr.String()) + // services.ResponseInternalServerError500ProcessError(w, err) + // return + // } + // out, err := cmd.CombinedOutput() + // log.Debugf("Exec output: %v", string(out)) + // if err != nil { + // log.Error("Faile to execute dpkg command:", err) + // services.ResponseInternalServerError500ProcessError(w, err) + // return + // } } else { err := global.ErrCMUnknownSoftwareFormat log.Error(err) diff --git a/features/fm/alarm.go b/features/fm/alarm.go index 06be5fe..c8d537e 100644 --- a/features/fm/alarm.go +++ b/features/fm/alarm.go @@ -252,7 +252,7 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) { tm, _ := time.Parse(time.RFC3339, alarmData.EventTime) log.Debugf("EventTime:%s tm:%d tm-datetime:%s", alarmData.EventTime, tm, tm.Local().Format(time.DateTime)) alarmData.ClearTime.Time = tm - if IsNeedToAckAlarm(valueJson, &alarmData) == true { + if IsNeedToAckAlarm(valueJson, &alarmData) { SetAlarmAckInfo(valueJson, &alarmData) affected, err := session.Where("ne_type=? and ne_id=? and alarm_id=? and alarm_status=1", alarmData.NeType, alarmData.NeId, alarmData.AlarmId). Cols("alarm_status", "clear_type", "clear_time", "ack_state", "ack_time", "ack_user"). @@ -285,7 +285,7 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) { log.Error("Failed to get alarm:", err) continue } - if has == true { + if has { seq, _ = strconv.Atoi(currentSeq) } @@ -320,7 +320,7 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) { } log.Debugf("neType=%s, neId=%s, eventTime=%s, severity=%s", alarmData.NeType, alarmData.NeId, alarmData.EventTime, severity) - if has == true && severity > alarmData.OrigSeverity { + if has && severity > alarmData.OrigSeverity { // update exist record _, err := session.Table("alarm"). Where("ne_type=? and ne_id=? and event_time=? and alarm_status=1", alarmData.NeType, alarmData.NeId, alarmData.EventTime). @@ -339,7 +339,7 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) { Where("alarm_id=? and ne_type=? and ne_id=? and alarm_status=1", alarmData.AlarmId, alarmData.NeType, alarmData.NeId). Exist() - if err == nil && has == true { + if err == nil && has { log.Warn("Exist the same alarm") continue } @@ -359,7 +359,7 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) { log.Debugf("neType=%s, neId=%s, currentSeq=%s activeAlarmNum=%d", alarmData.NeType, alarmData.NeId, currentSeq, activeAlarmNum) - if has == true { + if has { seq, _ := strconv.Atoi(currentSeq) alarmData.AlarmSeq = seq + 1 if alarmData.AlarmSeq > global.MaxInt32Number { @@ -384,7 +384,7 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) { } log.Debugf("neType=%s, neId=%s, eventTime=%s, severity=%s", alarmData.NeType, alarmData.NeId, alarmData.EventTime, severity) - if has == false || severity == alarmData.OrigSeverity { + if !has || severity == alarmData.OrigSeverity { alarmData.PerceivedSeverity = alarmData.OrigSeverity } else if severity > alarmData.OrigSeverity { alarmData.PerceivedSeverity = alarmData.OrigSeverity @@ -407,9 +407,9 @@ func PostAlarmFromNF(w http.ResponseWriter, r *http.Request) { alarmData.LocationInfo = fmt.Sprintf("Host:%s", r.RemoteAddr) } if alarmData.AddInfo == "" { - alarmData.LocationInfo = fmt.Sprintf("subNeInfo:%s", alarmData.NeType) + alarmData.AddInfo = fmt.Sprintf("subNeInfo:%s", alarmData.NeType) } - if IsNeedToAckAlarm(valueJson, &alarmData) == true { + if IsNeedToAckAlarm(valueJson, &alarmData) { SetAlarmAckInfo(valueJson, &alarmData) } log.Debug("alarmData:", alarmData) diff --git a/features/mml/mml.go b/features/mml/mml.go index 841b7fa..be2da12 100644 --- a/features/mml/mml.go +++ b/features/mml/mml.go @@ -21,10 +21,10 @@ import ( "github.com/gorilla/mux" ) -const ( - //经过测试,linux下,延时需要大于100ms - TIME_DELAY_AFTER_WRITE = 200 -) +// const ( +// //经过测试,linux下,延时需要大于100ms +// TIME_DELAY_AFTER_WRITE = 200 +// ) type Response struct { Data []string `json:"data"` @@ -48,6 +48,15 @@ var ( CustomUriOmMmlInt = config.UriPrefix + "/omManagement/{apiVersion}/mml/{neType}/{neId}" ) +// func init() { +// if config.GetYamlConfig().MML.Sleep != 0 { +// TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep) +// } +// if config.GetYamlConfig().MML.DeadLine != 0 { +// TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine) +// } +// } + func PostMMLToNF(w http.ResponseWriter, r *http.Request) { log.Debug("PostMMLToNF processing... ") @@ -56,6 +65,16 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) { log.Error("Request error:", err) return } + // 经过测试,linux下,延时需要大于100ms + var TIME_DELAY_AFTER_WRITE time.Duration = 200 + var TIME_DEAD_LINE time.Duration = 10 + if config.GetYamlConfig().MML.Sleep != 0 { + TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep) + } + if config.GetYamlConfig().MML.DeadLine != 0 { + TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine) + } + pack := "mml" vars := mux.Vars(r) module := vars["managedType"] @@ -72,7 +91,8 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) { log.Debugf("token:%s, method:%s, managementType:%s dbname:%s, tbname:%s pack:%s", token, r.Method, module, neType, neId[0], pack) - var buf [8192]byte + var buf [20 * 1024]byte + //buf := make([]byte, 0) var n int var mmlResult []string @@ -215,7 +235,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) { } defer conn.Close() - conn.SetDeadline(time.Now().Add(10 * time.Second)) + conn.SetDeadline(time.Now().Add(TIME_DEAD_LINE * time.Second)) loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password) _, err = conn.Write([]byte(loginStr)) @@ -254,7 +274,8 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) { re2 := regexp.MustCompile(`[\x00-\x08\x0B\x0C\x0E-\x1F\x7F\x1B]`) // 匹配空字符和包含␛的控制字符 //re := regexp.MustCompile(`[\x00-\x1F\x7F]`) // upf telnet buffer只能读取一次,需要去掉前面的多余字符 - result := re1.ReplaceAllString(string(buf[config.GetYamlConfig().MML.UpfHeaderLength:n-len(neType)-2]), "") + //result := re1.ReplaceAllString(string(buf[config.GetYamlConfig().MML.UpfHeaderLength:n-len(neType)-2]), "") + result := re1.ReplaceAllString(string(buf[0:n-len(neType)-2]), "") result = re2.ReplaceAllString(result, "") mmlResult = append(mmlResult, result) conn.Close() @@ -286,7 +307,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) { // services.ResponseWithJson(w, http.StatusOK, response) // return // } - conn.SetDeadline(time.Now().Add(10 * time.Second)) + conn.SetDeadline(time.Now().Add(TIME_DEAD_LINE * time.Second)) _, err = conn.Write([]byte(config.GetYamlConfig().MML.User + "\r\n")) if err != nil { @@ -405,7 +426,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) { // return // } - conn.SetDeadline(time.Now().Add(10 * time.Second)) + conn.SetDeadline(time.Now().Add(TIME_DEAD_LINE * time.Second)) loginStr := fmt.Sprintf("%s\n%s\n", config.GetYamlConfig().MML.User, config.GetYamlConfig().MML.Password) _, err = conn.Write([]byte(loginStr)) if err != nil { diff --git a/features/security/account.go b/features/security/account.go index 699c280..0e593d8 100644 --- a/features/security/account.go +++ b/features/security/account.go @@ -3,6 +3,7 @@ package security import ( "encoding/json" "fmt" + "image/color" "io" "net/http" "strconv" @@ -24,6 +25,7 @@ import ( "ems.agt/restagent/config" srcConfig "ems.agt/src/framework/config" "ems.agt/src/framework/redis" + "github.com/mojocn/base64Captcha" ) var ( @@ -308,3 +310,102 @@ func LoginOMC(w http.ResponseWriter, r *http.Request) { } ctx.JSON(w, 200, result.Err(nil)) } + +// 获取验证码 +// +// GET /captchaImage +func CaptchaImage(w http.ResponseWriter, r *http.Request) { + configService := sysConfigService.NewServiceSysConfig + + // 从数据库配置获取验证码开关 true开启,false关闭 + captchaEnabledStr := configService.SelectConfigValueByKey("sys.account.captchaEnabled") + captchaEnabled, err := strconv.ParseBool(captchaEnabledStr) + if err != nil { + captchaEnabled = false + } + if !captchaEnabled { + ctx.JSON(w, 200, result.Ok(map[string]any{ + "captchaEnabled": captchaEnabled, + })) + return + } + + // 生成唯一标识 + verifyKey := "" + data := map[string]any{ + "captchaEnabled": captchaEnabled, + "uuid": "", + "img": "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7", + } + + // char 字符验证 + driverCaptcha := &base64Captcha.DriverString{ + //Height png height in pixel. + Height: 40, + // Width Captcha png width in pixel. + Width: 120, + //NoiseCount text noise count. + NoiseCount: 4, + //Length random string length. + Length: 4, + //Source is a unicode which is the rand string from. + Source: "023456789abcdefghjkmnprstuvwxyz", + //ShowLineOptions := OptionShowHollowLine | OptionShowSlimeLine | OptionShowSineLine . + ShowLineOptions: base64Captcha.OptionShowHollowLine, + //BgColor captcha image background color (optional) + BgColor: &color.RGBA{ + R: 250, + G: 250, + B: 250, + A: 255, // 不透明 + }, + } + // 验证码生成 + id, question, answer := driverCaptcha.GenerateIdQuestionAnswer() + // 验证码表达式解析输出 + item, err := driverCaptcha.DrawCaptcha(question) + if err != nil { + log.Infof("Generate Id Question Answer %s : %v", question, err) + } else { + data["uuid"] = id + data["img"] = item.EncodeB64string() + verifyKey = cachekey.CAPTCHA_CODE_KEY + id + cache.SetLocalTTL(verifyKey, answer, 120*time.Second) + } + + // 本地开发下返回验证码结果,方便接口调试 + // text, ok := cache.GetLocalTTL(verifyKey) + // if ok { + // data["text"] = text.(string) + // } + + ctx.JSON(w, 200, result.Ok(data)) +} + +// 登录用户信息 +func UserInfo(w http.ResponseWriter, r *http.Request) { + loginUser, err := ctx.LoginUser(r) + if err != nil { + ctx.JSON(w, 200, result.OkData(err.Error())) + } + // 角色权限集合,管理员拥有所有权限 + userId := fmt.Sprint(loginUser.UserID) + isAdmin := srcConfig.IsAdmin(userId) + roles, perms := service.NewServiceAccount.RoleAndMenuPerms(userId, isAdmin) + + ctx.JSON(w, 200, result.OkData(map[string]any{ + "user": loginUser.User, + "roles": roles, + "permissions": perms, + })) +} + +// 登录用户路由信息 +func Routers(w http.ResponseWriter, r *http.Request) { + userID := ctx.LoginUserToUserID(r) + + // 前端路由,管理员拥有所有 + isAdmin := srcConfig.IsAdmin(userID) + buildMenus := service.NewServiceAccount.RouteMenus(userID, isAdmin) + ctx.JSON(w, 200, result.OkData(buildMenus)) +} diff --git a/features/state/getstate.go b/features/state/getstate.go index 8f3a937..dfdcc14 100644 --- a/features/state/getstate.go +++ b/features/state/getstate.go @@ -750,7 +750,7 @@ func GetStateFromNF(w http.ResponseWriter, r *http.Request) { restHostPort := fmt.Sprintf("http://127.0.0.1:%d", config.GetYamlConfig().Rest[0].Port) getNeInfoPattern := fmt.Sprintf(config.DefaultUriPrefix+"/databaseManagement/v1/elementType/%s/objectType/ne_info", config.GetYamlConfig().Database.Name) - getNeInfoURI := restHostPort + getNeInfoPattern + "?WHERE=status='0'" + getNeInfoURI := restHostPort + getNeInfoPattern + "?WHERE=status+in+('0','3')" log.Debug("getNeInfoPattern:", getNeInfoPattern) resp, err := client.R(). @@ -774,9 +774,9 @@ func GetStateFromNF(w http.ResponseWriter, r *http.Request) { getNeInfoURI := restHostPort + getNeInfoPattern neId := services.GetUriParamString(r, "ne_id", ",", true, true) if neId == "" { - getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status='0'+and+ne_type='%s'", neType) + getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status+in+('0','3')+and+ne_type='%s'", neType) } else { - getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status='0'+and+ne_type='%v'+and+ne_id+in+%v", neType, neId) + getNeInfoURI = getNeInfoURI + fmt.Sprintf("?WHERE=status+in+('0','3')+and+ne_type='%v'+and+ne_id+in+%v", neType, neId) } log.Debug("getNeInfoURI:", getNeInfoURI) @@ -802,7 +802,7 @@ func GetStateFromNF(w http.ResponseWriter, r *http.Request) { for _, ne := range neList { result := make(map[string]interface{}) log.Debugf("r.RemoteAddr: %s omcNeTypeLower: %s", r.RemoteAddr, omcNeTypeLower) - log.Debug("ne: ", ne) + log.Trace("ne: ", ne) //if strings.ToLower(ne.NeType) != omcNeTypeLower || !strings.Contains(r.RemoteAddr, ne.Ip) { if strings.ToLower(ne.NeType) != omcNeTypeLower { hostUri := fmt.Sprintf("http://%s:%v", ne.Ip, ne.Port) @@ -881,12 +881,13 @@ func GetEMSState(ip string) *SysState { version = global.Version } hostName, _ := os.Hostname() + dbInfo, _ := dborm.XormGetMySQLVersion() emsState := &SysState{ HostName: hostName, OsInfo: getUnameStr(), - DbInfo: "mysql Ver 15.1 Distrib 10.3.35-MariaDB, for Linux (aarch64) using readline 5.1", + DbInfo: dbInfo, IpAddr: []string{ip}, - Port: 3030, + Port: config.GetYamlConfig().Rest[0].Port, Version: version, Capability: 9999999, SerialNum: config.GetYamlConfig().OMC.Sn, diff --git a/features/ue/ue.go b/features/ue/ue.go index fb20dcd..29a28d8 100644 --- a/features/ue/ue.go +++ b/features/ue/ue.go @@ -107,7 +107,7 @@ func init() { return 0, errors.New("quota exceeded") }) */ - client.SetTimeout(3 * time.Second) + client.SetTimeout(500 * time.Millisecond) } // Get AvailableAMFs from NSSF