mirror of
				https://github.com/bjdgyc/anylink.git
				synced 2025-11-04 11:06:22 +08:00 
			
		
		
		
	优化代码
This commit is contained in:
		@@ -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
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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服务器连接异常, 请检测服务器和端口")
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user