Merge pull request #362 from bjdgyc/dev

修复 radius 验证测试 panic 的问题
This commit is contained in:
bjdgyc 2025-03-25 17:38:10 +08:00 committed by GitHub
commit 805498e270
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package admin
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"runtime/debug"
"time" "time"
"github.com/bjdgyc/anylink/base" "github.com/bjdgyc/anylink/base"
@ -120,3 +121,17 @@ func authMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(fn) return http.HandlerFunc(fn)
} }
func recoverHttp(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
stack := debug.Stack()
base.Error(err, string(stack))
// http.Error(w, "Internal Server Error", 500)
RespError(w, 500, "Internal Server Error")
}
}()
next.ServeHTTP(w, r)
})
}

View File

@ -21,6 +21,7 @@ var UiData embed.FS
func StartAdmin() { func StartAdmin() {
r := mux.NewRouter() r := mux.NewRouter()
r.Use(recoverHttp, authMiddleware, handlers.CompressHandler)
// 所有路由添加安全头 // 所有路由添加安全头
r.Use(func(next http.Handler) http.Handler { r.Use(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
@ -29,8 +30,6 @@ func StartAdmin() {
next.ServeHTTP(w, req) next.ServeHTTP(w, req)
}) })
}) })
r.Use(authMiddleware)
r.Use(handlers.CompressHandler)
// 监控检测 // 监控检测
r.HandleFunc("/status.html", func(w http.ResponseWriter, r *http.Request) { r.HandleFunc("/status.html", func(w http.ResponseWriter, r *http.Request) {

View File

@ -51,6 +51,9 @@ admin_addr = ":8800"
#开启tcp proxy protocol协议 #开启tcp proxy protocol协议
proxy_protocol = false proxy_protocol = false
#开启go标准库http.Server的日志
http_server_log=false
#虚拟网络类型[tun macvtap tap] #虚拟网络类型[tun macvtap tap]
link_mode = "tun" link_mode = "tun"

View File

@ -75,8 +75,11 @@ func (auth AuthRadius) checkUser(name, pwd string, g *Group, ext map[string]inte
return fmt.Errorf("%s %s", name, "Radius set nasip 出现错误") return fmt.Errorf("%s %s", name, "Radius set nasip 出现错误")
} }
} }
macAddr := ext["mac_addr"].(string) macAddr := ""
base.Trace("AuthRadius", ext, macAddr) if ext["mac_addr"] != nil {
macAddr = ext["mac_addr"].(string)
base.Trace("AuthRadius", ext, macAddr)
}
if macAddr != "" { if macAddr != "" {
err = rfc2865.CallingStationID_AddString(packet, macAddr) err = rfc2865.CallingStationID_AddString(packet, macAddr)
if err != nil { if err != nil {
@ -94,5 +97,4 @@ func (auth AuthRadius) checkUser(name, pwd string, g *Group, ext map[string]inte
return fmt.Errorf("%s %s", name, "Radius用户名或密码错误") return fmt.Errorf("%s %s", name, "Radius用户名或密码错误")
} }
return nil return nil
} }