diff --git a/cmd/templaterender/render.go b/cmd/templaterender/render.go index 70fd8c6..a92ba10 100644 --- a/cmd/templaterender/render.go +++ b/cmd/templaterender/render.go @@ -93,7 +93,7 @@ func main() { state.Agents = append(state.Agents, agent) client := models.Client{ PublicId: "c1", - ClientId: 3, + ClientId: "3", StartTime: time.Now().In(japan), SessionType: "sftp", } diff --git a/pkg/comms/agentlistener.go b/pkg/comms/agentlistener.go index 661c85a..2188ccd 100644 --- a/pkg/comms/agentlistener.go +++ b/pkg/comms/agentlistener.go @@ -3,7 +3,6 @@ package comms import ( "converge/pkg/support/websocketutil" "net" - "strconv" ) type AgentListener struct { @@ -42,7 +41,7 @@ func (listener AgentListener) Accept() (net.Conn, error) { conn.Close() return nil, err } - return NewLocalAddrHackConn(conn, strconv.Itoa(clientInfo.ClientId)), nil + return NewLocalAddrHackConn(conn, clientInfo.ClientId), nil } func (listener AgentListener) Close() error { diff --git a/pkg/comms/events.go b/pkg/comms/events.go index c47fb70..de75660 100644 --- a/pkg/comms/events.go +++ b/pkg/comms/events.go @@ -25,7 +25,7 @@ type AgentInfo struct { } type ClientInfo struct { - ClientId int + ClientId string } type SessionInfo struct { diff --git a/pkg/models/client.go b/pkg/models/client.go index 17136ea..9861537 100644 --- a/pkg/models/client.go +++ b/pkg/models/client.go @@ -6,7 +6,7 @@ import ( type Client struct { PublicId string - ClientId int + ClientId string StartTime time.Time SessionType string } diff --git a/pkg/server/converge/admin.go b/pkg/server/converge/admin.go index f9d5866..dc1ee4f 100644 --- a/pkg/server/converge/admin.go +++ b/pkg/server/converge/admin.go @@ -46,7 +46,7 @@ func NewClient(publicId string, clientConn iowrappers2.ReadWriteAddrCloser, return &ClientConnection{ Client: models.Client{ PublicId: publicId, - ClientId: clientIdGenerator.IncrementAndGet(), + ClientId: strconv.Itoa(clientIdGenerator.IncrementAndGet()), StartTime: time.Now(), }, agent: agentConn, @@ -107,7 +107,7 @@ func (admin *Admin) logStatus() { lines = append(lines, fmt.Sprintf(format, "CLIENT", "AGENT", "ACTIVE_SINCE", "REMOTE_ADDRESS", "SESSION_TYPE")) for _, client := range admin.clients { lines = append(lines, fmt.Sprintf(format, - strconv.Itoa(client.ClientId), + client.ClientId, client.PublicId, client.StartTime.Format(time.DateTime), client.client.RemoteAddr(), @@ -248,7 +248,7 @@ func (admin *Admin) RemoveClient(client *ClientConnection) error { admin.mutex.Lock() defer admin.mutex.Unlock() - log.Printf("Removing client: '%d' created at %s\n", client.ClientId, + log.Printf("Removing client: '%s' created at %s\n", client.ClientId, client.StartTime.Format(time.DateTime)) // try to explicitly close connection to the agent. _ = client.agent.Close() @@ -293,7 +293,7 @@ func (admin *Admin) Register(publicId string, conn io.ReadWriteCloser) error { for _, client := range admin.clients { // a bit hacky. There should be at most one client that has an unset session // Very unlikely for multiple sessions to start at the same point in time. - if strconv.Itoa(client.ClientId) == session.ClientId { + if client.ClientId == session.ClientId { client.SessionType = session.SessionType break } diff --git a/pkg/server/templates/sessions.templ b/pkg/server/templates/sessions.templ index 20070ee..9686ac0 100644 --- a/pkg/server/templates/sessions.templ +++ b/pkg/server/templates/sessions.templ @@ -2,7 +2,6 @@ package templates import ( "converge/pkg/models" - "strconv" "time" _ "time/tzdata" ) @@ -75,7 +74,7 @@ templ State(state *models.State, location *time.Location) { for _, client := range state.Clients { - {strconv.Itoa(client.ClientId)} + {client.ClientId} {client.StartTime.In(location).Format(time.DateTime)} {client.SessionType} {client.PublicId}