diff --git a/server/handler/link_auth.go b/server/handler/link_auth.go index f25bb49..300710c 100644 --- a/server/handler/link_auth.go +++ b/server/handler/link_auth.go @@ -1,9 +1,11 @@ package handler import ( + "crypto/md5" "encoding/xml" "fmt" "io" + "net" "net/http" "strings" "text/template" @@ -87,6 +89,15 @@ func LinkAuth(w http.ResponseWriter, r *http.Request) { sess.Group = cr.GroupSelect sess.MacAddr = strings.ToLower(cr.MacAddressList.MacAddress) sess.UniqueIdGlobal = cr.DeviceId.UniqueIdGlobal + // 获取客户端mac地址 + macHw, err := net.ParseMAC(sess.MacAddr) + if err != nil { + sum := md5.Sum([]byte(sess.UniqueIdGlobal)) + macHw = sum[0:5] // 5个byte + macHw = append([]byte{0x02}, macHw...) + sess.MacAddr = macHw.String() + } + sess.MacHw = macHw other := &dbdata.SettingOther{} _ = dbdata.SettingGet(other) rd := RequestData{SessionId: sess.Sid, SessionToken: sess.Sid + "@" + sess.Token, diff --git a/server/handler/link_cstp.go b/server/handler/link_cstp.go index 1618b47..97a9fb3 100644 --- a/server/handler/link_cstp.go +++ b/server/handler/link_cstp.go @@ -12,6 +12,7 @@ import ( ) func LinkCstp(conn net.Conn, bufRW *bufio.ReadWriter, cSess *sessdata.ConnSession) { + base.Debug("LinkCstp connect ip:", cSess.IpAddr, "user:", cSess.Username, "rip:", conn.RemoteAddr()) defer func() { base.Debug("LinkCstp return", cSess.IpAddr) _ = conn.Close() diff --git a/server/handler/link_dtls.go b/server/handler/link_dtls.go index e674ff2..23c6e86 100644 --- a/server/handler/link_dtls.go +++ b/server/handler/link_dtls.go @@ -10,7 +10,7 @@ import ( ) func LinkDtls(conn net.Conn, cSess *sessdata.ConnSession) { - base.Debug("LinkDtls connect ip:", cSess.IpAddr, "udp-rip:", conn.RemoteAddr()) + base.Debug("LinkDtls connect ip:", cSess.IpAddr, "user:", cSess.Username, "udp-rip:", conn.RemoteAddr()) dSess := cSess.NewDtlsConn() if dSess == nil { // 创建失败,直接关闭链接 diff --git a/server/handler/pool.go b/server/handler/pool.go old mode 100755 new mode 100644 diff --git a/server/sessdata/session.go b/server/sessdata/session.go index 7a38710..b2a2834 100644 --- a/server/sessdata/session.go +++ b/server/sessdata/session.go @@ -1,7 +1,6 @@ package sessdata import ( - "crypto/md5" "fmt" "math/rand" "net" @@ -32,6 +31,7 @@ type ConnSession struct { IpAddr net.IP // 分配的ip地址 LocalIp net.IP MacHw net.HardwareAddr // 客户端mac地址,从Session取出 + Username string RemoteAddr string Mtu int IfName string @@ -70,6 +70,7 @@ type Session struct { DtlsSid string // dtls协议的 session_id MacAddr string // 客户端mac地址 UniqueIdGlobal string // 客户端唯一标示 + MacHw net.HardwareAddr Username string // 用户名 Group string AuthStep string @@ -147,6 +148,7 @@ func (s *Session) NewConn() *ConnSession { s.mux.RLock() active := s.IsActive macAddr := s.MacAddr + macHw := s.MacHw username := s.Username s.mux.RUnlock() if active { @@ -157,14 +159,6 @@ func (s *Session) NewConn() *ConnSession { if !limit { return nil } - // 获取客户端mac地址 - macHw, err := net.ParseMAC(macAddr) - if err != nil { - sum := md5.Sum([]byte(s.UniqueIdGlobal)) - macHw = sum[0:5] // 5个byte - macHw = append([]byte{0x02}, macHw...) - macAddr = macHw.String() - } ip := AcquireIp(username, macAddr) if ip == nil { LimitClient(username, true) @@ -173,7 +167,7 @@ func (s *Session) NewConn() *ConnSession { // 查询group信息 group := &dbdata.Group{} - err = dbdata.One("Name", s.Group, group) + err := dbdata.One("Name", s.Group, group) if err != nil { base.Error(err) return nil @@ -182,6 +176,7 @@ func (s *Session) NewConn() *ConnSession { cSess := &ConnSession{ Sess: s, MacHw: macHw, + Username: username, IpAddr: ip, closeOnce: sync.Once{}, CloseChan: make(chan struct{}), @@ -229,6 +224,11 @@ func (cs *ConnSession) Close() { cs.Sess.LastLogin = time.Now() cs.Sess.CSess = nil + dSess := cs.GetDtlsSession() + if dSess != nil { + dSess.Close() + } + ReleaseIp(cs.IpAddr, cs.Sess.MacAddr) LimitClient(cs.Sess.Username, true) }) @@ -272,7 +272,7 @@ func (cs *ConnSession) GetDtlsSession() *DtlsSession { return nil } -const BandwidthPeriodSec = 2 // 流量速率统计周期(秒) +const BandwidthPeriodSec = 10 // 流量速率统计周期(秒) func (cs *ConnSession) ratePeriod() { tick := time.NewTicker(time.Second * BandwidthPeriodSec) diff --git a/server/sessdata/statsinfo.go b/server/sessdata/statsinfo.go index cc6f762..e07a0f2 100644 --- a/server/sessdata/statsinfo.go +++ b/server/sessdata/statsinfo.go @@ -11,7 +11,7 @@ import ( ) const ( - StatsCycleSec = 5 // 统计周期(秒) + StatsCycleSec = 10 // 统计周期(秒) AddCycleSec = 60 // 记录到数据表周期(秒) ) diff --git a/web/src/pages/Home.vue b/web/src/pages/Home.vue index 6f8c9bd..9c071fe 100644 --- a/web/src/pages/Home.vue +++ b/web/src/pages/Home.vue @@ -190,7 +190,7 @@ export default { this.getAllStats() const chartsTimer = setInterval(() => { this.getAllStats() - }, 5000); + }, 10000); this.$once('hook:beforeDestroy', () => { clearInterval(chartsTimer); }) diff --git a/web/src/pages/user/Online.vue b/web/src/pages/user/Online.vue index a2d339e..f9041cb 100644 --- a/web/src/pages/user/Online.vue +++ b/web/src/pages/user/Online.vue @@ -128,7 +128,7 @@ export default { const chatTimer = setInterval(() => { this.getData(); - }, 2000); + }, 10000); this.$once('hook:beforeDestroy', () => { clearInterval(chatTimer);