添加支持 radius 的 nasip

This commit is contained in:
bjdgyc 2024-09-10 13:12:01 +08:00
parent 00c5425990
commit 4b78232e1d
2 changed files with 22 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"net"
"reflect" "reflect"
"time" "time"
@ -15,6 +16,7 @@ import (
type AuthRadius struct { type AuthRadius struct {
Addr string `json:"addr"` Addr string `json:"addr"`
Secret string `json:"secret"` Secret string `json:"secret"`
Nasip string `json:"nasip"`
} }
func init() { func init() {
@ -57,8 +59,22 @@ func (auth AuthRadius) checkUser(name, pwd string, g *Group) error {
} }
// radius认证时设置超时3秒 // radius认证时设置超时3秒
packet := radius.New(radius.CodeAccessRequest, []byte(auth.Secret)) packet := radius.New(radius.CodeAccessRequest, []byte(auth.Secret))
rfc2865.UserName_SetString(packet, name) err = rfc2865.UserName_SetString(packet, name)
rfc2865.UserPassword_SetString(packet, pwd) if err != nil {
return fmt.Errorf("%s %s", name, "Radius set name 出现错误")
}
err = rfc2865.UserPassword_SetString(packet, pwd)
if err != nil {
return fmt.Errorf("%s %s", name, "Radius set pwd 出现错误")
}
if auth.Nasip != "" {
nasip := net.ParseIP(auth.Nasip)
err = rfc2865.NASIPAddress_Set(packet, nasip)
if err != nil {
return fmt.Errorf("%s %s", name, "Radius set nasip 出现错误")
}
}
ctx, done := context.WithTimeout(context.Background(), 3*time.Second) ctx, done := context.WithTimeout(context.Background(), 3*time.Second)
defer done() defer done()
response, err := radius.Exchange(ctx, packet, auth.Addr) response, err := radius.Exchange(ctx, packet, auth.Addr)

View File

@ -298,6 +298,9 @@
:rules="this.ruleForm.auth.type== 'radius' ? this.rules['auth.radius.secret'] : [{ required: false }]"> :rules="this.ruleForm.auth.type== 'radius' ? this.rules['auth.radius.secret'] : [{ required: false }]">
<el-input v-model="ruleForm.auth.radius.secret" placeholder=""></el-input> <el-input v-model="ruleForm.auth.radius.secret" placeholder=""></el-input>
</el-form-item> </el-form-item>
<el-form-item label="Nasip" prop="auth.radius.nasip">
<el-input v-model="ruleForm.auth.radius.nasip" placeholder=""></el-input>
</el-form-item>
</template> </template>
<template v-if="ruleForm.auth.type == 'ldap'"> <template v-if="ruleForm.auth.type == 'ldap'">
@ -547,7 +550,7 @@ export default {
maxRouteRows: 2500, maxRouteRows: 2500,
defAuth: { defAuth: {
type: 'local', type: 'local',
radius: {addr: "", secret: ""}, radius: {addr: "", secret: "", nasip: ""},
ldap: { ldap: {
addr: "", addr: "",
tls: false, tls: false,