updated ipbl websocket feat

This commit is contained in:
Paul 2023-04-10 11:57:25 +02:00
parent abc02caf92
commit 447f756922
3 changed files with 12 additions and 11 deletions

View File

@ -3,7 +3,6 @@ package routers
import ( import (
"context" "context"
"fmt" "fmt"
"log"
"net/http" "net/http"
"strconv" "strconv"
@ -87,7 +86,6 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
} }
numinsert, numupdate, _ := models.InsertIPBulk(session, &ips) numinsert, numupdate, _ := models.InsertIPBulk(session, &ips)
msg = fmt.Sprintf("Inserted %d IP, Updated %d IP", numinsert, numupdate) msg = fmt.Sprintf("Inserted %d IP, Updated %d IP", numinsert, numupdate)
log.Println(msg)
return Result(c, err, msg) return Result(c, err, msg)
}) })
e.POST("/event", func(c echo.Context) (err error) { e.POST("/event", func(c echo.Context) (err error) {

View File

@ -43,6 +43,15 @@ func WelcomeAgents(ws *websocket.Conn, welcome WSWelcome, t string) {
} }
} }
func gcConn(conn *websocket.Conn) (err error) {
for index, value := range LISTENERS {
if value.ConnectionPS == conn || value.ConnectionRR == conn {
delete(LISTENERS, index)
}
}
return err
}
type ConnectionInfo struct { type ConnectionInfo struct {
ConnectionPS *websocket.Conn ConnectionPS *websocket.Conn
ConnectionRR *websocket.Conn ConnectionRR *websocket.Conn
@ -52,12 +61,3 @@ type ConnectionInfo struct {
type WSWelcome struct { type WSWelcome struct {
Hostname string Hostname string
} }
func gcConn(conn *websocket.Conn, t string) (err error) {
for index, value := range LISTENERS {
if value.ConnectionPS == conn {
delete(LISTENERS, index)
}
}
return err
}

View File

@ -80,11 +80,14 @@ func HandleWSRR(c echo.Context, cfg *config.Config) error {
err = websocket.Message.Send(value.ConnectionPS, msg) err = websocket.Message.Send(value.ConnectionPS, msg)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }
} }
default: default:
} }
gcConn(ws)
err = websocket.Message.Send(ws, "OK") err = websocket.Message.Send(ws, "OK")
if err != nil { if err != nil {
log.Println(err) log.Println(err)