diff --git a/server/dbdata/group.go b/server/dbdata/group.go index 831c194..4effbd2 100644 --- a/server/dbdata/group.go +++ b/server/dbdata/group.go @@ -205,9 +205,9 @@ func checkRadiusData(auth map[string]interface{}) error { if !ValidateIpPort(radisConf.Addr) { return errors.New("Radius的服务器地址填写有误") } - // freeradius官网最大8000字符, 这里限制800 - if len(radisConf.Secret) < 8 || len(radisConf.Secret) > 800 { - return errors.New("Radius的密钥长度需在8~800个字符之间") + // freeradius官网最大8000字符, 这里限制200 + if len(radisConf.Secret) < 8 || len(radisConf.Secret) > 200 { + return errors.New("Radius的密钥长度需在8~200个字符之间") } return nil } diff --git a/server/dbdata/user.go b/server/dbdata/user.go index 5f634f7..3db7461 100644 --- a/server/dbdata/user.go +++ b/server/dbdata/user.go @@ -86,16 +86,7 @@ func CheckUser(name, pwd, group string) error { case "", "local": return checkLocalUser(name, pwd, group) case "radius": - radisConf := AuthRadius{} - bodyBytes, err := json.Marshal(groupData.Auth["radius"]) - if err != nil { - fmt.Errorf("%s %s", name, "Radius出现Marshal错误") - } - err = json.Unmarshal(bodyBytes, &radisConf) - if err != nil { - fmt.Errorf("%s %s", name, "Radius出现Unmarshal错误") - } - return checkRadiusUser(name, pwd, radisConf) + return checkRadiusUser(name, pwd, groupData.Auth) default: return fmt.Errorf("%s %s", name, "无效的认证类型") } @@ -144,13 +135,26 @@ func checkLocalUser(name, pwd, group string) error { return nil } -func checkRadiusUser(name string, pwd string, raduisConf AuthRadius) error { - packet := radius.New(radius.CodeAccessRequest, []byte(raduisConf.Secret)) +func checkRadiusUser(name string, pwd string, auth map[string]interface{}) error { + if _, ok := auth["radius"]; !ok { + fmt.Errorf("%s %s", name, "Radius的radius值不存在") + } + radiusConf := AuthRadius{} + bodyBytes, err := json.Marshal(auth["radius"]) + if err != nil { + fmt.Errorf("%s %s", name, "Radius Marshal出现错误") + } + err = json.Unmarshal(bodyBytes, &radiusConf) + if err != nil { + fmt.Errorf("%s %s", name, "Radius Unmarshal出现错误") + } + // radius认证时,设置超时3秒 + packet := radius.New(radius.CodeAccessRequest, []byte(radiusConf.Secret)) rfc2865.UserName_SetString(packet, name) rfc2865.UserPassword_SetString(packet, pwd) ctx, done := context.WithTimeout(context.Background(), 3*time.Second) defer done() - response, err := radius.Exchange(ctx, packet, raduisConf.Addr) + response, err := radius.Exchange(ctx, packet, radiusConf.Addr) if err != nil { return fmt.Errorf("%s %s", name, "Radius服务器连接异常, 请检测服务器和端口") } diff --git a/web/src/pages/group/List.vue b/web/src/pages/group/List.vue index 8524c53..446584d 100644 --- a/web/src/pages/group/List.vue +++ b/web/src/pages/group/List.vue @@ -451,7 +451,7 @@ export default { arr.push({val: "", action: "allow", port: 0}); }, submitForm(formName) { - this.$refs[formName].validate((valid, obj) => { + this.$refs[formName].validate((valid) => { if (!valid) { console.log('error submit!!'); return false;