From 4b78232e1df3836c0ef4ce8a93a75daa11305815 Mon Sep 17 00:00:00 2001 From: bjdgyc Date: Tue, 10 Sep 2024 13:12:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=94=AF=E6=8C=81=20radius?= =?UTF-8?q?=20=E7=9A=84=20=20nasip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/dbdata/userauth_radius.go | 20 ++++++++++++++++++-- web/src/pages/group/List.vue | 5 ++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/server/dbdata/userauth_radius.go b/server/dbdata/userauth_radius.go index 4d15eb1c..95d28536 100644 --- a/server/dbdata/userauth_radius.go +++ b/server/dbdata/userauth_radius.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "net" "reflect" "time" @@ -15,6 +16,7 @@ import ( type AuthRadius struct { Addr string `json:"addr"` Secret string `json:"secret"` + Nasip string `json:"nasip"` } func init() { @@ -57,8 +59,22 @@ func (auth AuthRadius) checkUser(name, pwd string, g *Group) error { } // radius认证时,设置超时3秒 packet := radius.New(radius.CodeAccessRequest, []byte(auth.Secret)) - rfc2865.UserName_SetString(packet, name) - rfc2865.UserPassword_SetString(packet, pwd) + err = rfc2865.UserName_SetString(packet, name) + 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) defer done() response, err := radius.Exchange(ctx, packet, auth.Addr) diff --git a/web/src/pages/group/List.vue b/web/src/pages/group/List.vue index 8c4d9973..6267d61b 100644 --- a/web/src/pages/group/List.vue +++ b/web/src/pages/group/List.vue @@ -298,6 +298,9 @@ :rules="this.ruleForm.auth.type== 'radius' ? this.rules['auth.radius.secret'] : [{ required: false }]"> + + +