fix: 获取网元状态信息错误
This commit is contained in:
@@ -205,34 +205,6 @@ type NeInfo struct {
|
||||
UpdateTime time.Time `json:"updateTime" xorm:"<-"`
|
||||
}
|
||||
|
||||
func XormGetMySQLVersion() (string, error) {
|
||||
var versionInfo string = ""
|
||||
|
||||
var ver, verComment, verCompileOS, verCompile string
|
||||
_, err := xEngine.SQL("SHOW VARIABLES LIKE 'version'").Get(&ver, &ver)
|
||||
if err != nil {
|
||||
return versionInfo, err
|
||||
}
|
||||
|
||||
_, err = xEngine.SQL("SHOW VARIABLES LIKE 'version_comment'").Get(&verComment, &verComment)
|
||||
if err != nil {
|
||||
return versionInfo, err
|
||||
}
|
||||
|
||||
_, err = xEngine.SQL("SHOW VARIABLES LIKE 'version_compile_os'").Get(&verCompileOS, &verCompileOS)
|
||||
if err != nil {
|
||||
return versionInfo, err
|
||||
}
|
||||
|
||||
_, err = xEngine.SQL("SHOW VARIABLES LIKE 'version_compile_machine'").Get(&verCompile, &verCompile)
|
||||
if err != nil {
|
||||
return versionInfo, err
|
||||
}
|
||||
|
||||
versionInfo = fmt.Sprintf("%s %s, for %s (%s)", ver, verComment, verCompileOS, verCompile)
|
||||
return versionInfo, nil
|
||||
}
|
||||
|
||||
func XormGetNeInfo(neType string, neId string) (*NeInfo, error) {
|
||||
log.Debug("XormGetNeInfo processing... ")
|
||||
|
||||
@@ -394,19 +366,19 @@ func XormParseResult(body []byte) ([]NeInfo, error) {
|
||||
var neInfo []NeInfo
|
||||
var re interface{}
|
||||
if data["data"] == nil {
|
||||
return nil, errors.New("The data is Not found")
|
||||
return nil, errors.New("the data is not found")
|
||||
}
|
||||
for _, d := range data["data"].([]interface{}) {
|
||||
if d == nil {
|
||||
return nil, errors.New("The data is Not found")
|
||||
return nil, errors.New("the data is Not found")
|
||||
}
|
||||
for _, re = range d.(map[string]interface{}) {
|
||||
if re == nil {
|
||||
return nil, errors.New("The data is Not found")
|
||||
return nil, errors.New("the data is Not found")
|
||||
}
|
||||
for _, rc := range re.([]interface{}) {
|
||||
if rc == nil {
|
||||
return nil, errors.New("The data is Not found")
|
||||
return nil, errors.New("the data is Not found")
|
||||
}
|
||||
var s NeInfo
|
||||
record := rc.(map[string]interface{})
|
||||
@@ -492,9 +464,7 @@ func ConstructUpdateSQL(tableName string, updateData interface{}, whereCondition
|
||||
func ConstructDeleteSQL(tableName string, whereCondition string) string {
|
||||
log.Debug("ConstructDeleteSQL processing... ")
|
||||
|
||||
var sql string
|
||||
|
||||
sql = "DELETE from " + tableName + " WHERE " + whereCondition
|
||||
var sql string = "DELETE from " + tableName + " WHERE " + whereCondition
|
||||
log.Debug("sql:", sql)
|
||||
return sql
|
||||
}
|
||||
@@ -526,7 +496,7 @@ func GetTableByWhere(whereCondition string, tableName string) (*[]interface{}, e
|
||||
if err != nil {
|
||||
log.Errorf("Failed to get table %s from database:%v", tableName, err)
|
||||
return nil, err
|
||||
} else if has == false {
|
||||
} else if !has {
|
||||
log.Infof("Not found table %s from database:where=%d", tableName, whereCondition)
|
||||
return nil, nil
|
||||
}
|
||||
@@ -543,7 +513,7 @@ func GetTableById(id int, tableName string) (*[]interface{}, error) {
|
||||
if err != nil {
|
||||
log.Errorf("Failed to get table %s from database:id=%d, %v", tableName, id, err)
|
||||
return nil, err
|
||||
} else if has == false {
|
||||
} else if !has {
|
||||
log.Infof("Not found table %s from database:id=%d", tableName, id)
|
||||
return nil, nil
|
||||
}
|
||||
@@ -576,112 +546,8 @@ func XormUpdateTableByWhere(whereCondition string, tableName string, tbInfo inte
|
||||
return affected, nil
|
||||
}
|
||||
|
||||
// 记录密码登录错误次数
|
||||
func pwdErrCountAdd(accountId, profileStr string, reset bool) int {
|
||||
if profileStr == "" {
|
||||
profileStr = "{}"
|
||||
}
|
||||
profile := make(map[string]any)
|
||||
count := 0
|
||||
timeMlli := time.Now().UnixMilli()
|
||||
|
||||
// 反序列去值
|
||||
err := json.Unmarshal([]byte(profileStr), &profile)
|
||||
if err != nil {
|
||||
log.Error("json Unmarshal:%s", err.Error())
|
||||
return 0
|
||||
}
|
||||
|
||||
// 读取配置信息 登录策略设置
|
||||
result, err := XormGetConfig("Security", "loginSecurity")
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
data := make(map[string]any)
|
||||
err = json.Unmarshal([]byte(result["value_json"].(string)), &data)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
limitNum := data["limit_num"].(string)
|
||||
passwordLimitTime := data["password_limit_time"].(string)
|
||||
|
||||
// 重置
|
||||
if reset {
|
||||
// xEngine.Exec("UPDATE user SET status = 'Active' WHERE account_id = ?", accountId)
|
||||
profile["pwdErrCount"] = float64(0)
|
||||
profile["pwdErrTime"] = 0
|
||||
} else {
|
||||
if v, ok := profile["pwdErrTime"]; ok && v != nil {
|
||||
// 获取当前时间
|
||||
currentTime := time.Now()
|
||||
|
||||
// 获取给定的时间戳(毫秒)
|
||||
timestamp := int64(v.(float64)) // 要比较的时间戳(毫秒)
|
||||
// 将时间戳转换为时间类型
|
||||
tm := time.Unix(timestamp/1000, (timestamp%1000)*int64(time.Millisecond))
|
||||
|
||||
// 计算当前时间与给定时间之间的差值
|
||||
duration := currentTime.Sub(tm)
|
||||
|
||||
// // 比较差值是否超过30分钟
|
||||
// if duration.Minutes() > 30 {
|
||||
// xEngine.Exec("UPDATE user SET status = 'Active' WHERE account_id = ?", accountId)
|
||||
// profile["pwdErrCount"] = float64(0)
|
||||
// profile["pwdErrTime"] = 0
|
||||
// }
|
||||
|
||||
// 比较差值是否小于限定时间s
|
||||
passwordLimitTimeInt, err := strconv.Atoi(passwordLimitTime)
|
||||
if err != nil {
|
||||
passwordLimitTimeInt = 0
|
||||
}
|
||||
if duration.Seconds() > float64(passwordLimitTimeInt) {
|
||||
// xEngine.Exec("UPDATE user SET status = 'Active' WHERE account_id = ?", accountId)
|
||||
profile["pwdErrCount"] = float64(0)
|
||||
profile["pwdErrTime"] = 0
|
||||
}
|
||||
}
|
||||
|
||||
if v, ok := profile["pwdErrCount"]; ok && v != nil {
|
||||
count = int(v.(float64)) + 1
|
||||
profile["pwdErrCount"] = count
|
||||
profile["pwdErrTime"] = timeMlli
|
||||
// 错误最大后锁定
|
||||
limitNumInt, err := strconv.Atoi(limitNum)
|
||||
if err != nil {
|
||||
limitNumInt = 0
|
||||
}
|
||||
// if count == limitNumInt {
|
||||
// _, err := xEngine.Exec("UPDATE user SET status = 'Locked' WHERE account_id = ?", accountId)
|
||||
// if err != nil {
|
||||
// return count
|
||||
// }
|
||||
// }
|
||||
if count >= limitNumInt {
|
||||
return count
|
||||
}
|
||||
} else {
|
||||
count = 1
|
||||
profile["pwdErrCount"] = count
|
||||
profile["pwdErrTime"] = timeMlli
|
||||
}
|
||||
}
|
||||
|
||||
// 序列后记录
|
||||
strByte, err := json.Marshal(profile)
|
||||
if err != nil {
|
||||
log.Error("json Marshal:%s", err.Error())
|
||||
return count
|
||||
}
|
||||
_, err = xEngine.Exec("UPDATE user SET profile = ? WHERE account_id = ?", string(strByte), accountId)
|
||||
if err != nil {
|
||||
return count
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func XormIsExistUser(accid string) (bool, error) {
|
||||
log.Info("XormIsExistUser processing... ")
|
||||
log.Info("xormIsExistUser processing... ")
|
||||
|
||||
exist, err := xEngine.Table("user").
|
||||
Where("account_id=?", accid).
|
||||
|
||||
Reference in New Issue
Block a user