From b5ed0800cf8b38b4359e446ce44c504e5f35e433 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Tue, 16 Jan 2024 18:24:30 +0100 Subject: [PATCH] Add address host connected from to the host info Provide an easy way to see where a host is connecting from in the web UI and clusterioctl list. --- packages/controller/src/HostConnection.ts | 2 ++ packages/controller/src/HostInfo.ts | 8 +++++++- packages/controller/src/WsServer.ts | 2 +- packages/lib/src/data/messages_host.ts | 7 +++++-- packages/web_ui/src/components/HostViewPage.tsx | 1 + 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/controller/src/HostConnection.ts b/packages/controller/src/HostConnection.ts index 7c2bdc4c..f4cf1d84 100644 --- a/packages/controller/src/HostConnection.ts +++ b/packages/controller/src/HostConnection.ts @@ -23,6 +23,7 @@ export default class HostConnection extends BaseConnection { registerData: lib.RegisterHostData, connector: WsServerConnector, controller: Controller, + remoteAddress: string, ) { super(connector, controller); @@ -35,6 +36,7 @@ export default class HostConnection extends BaseConnection { registerData.version, this.plugins, true, + remoteAddress, previousHostInfo?.publicAddress, previousHostInfo?.tokenValidAfter, 0, diff --git a/packages/controller/src/HostInfo.ts b/packages/controller/src/HostInfo.ts index 6b523c9c..7a7a105e 100644 --- a/packages/controller/src/HostInfo.ts +++ b/packages/controller/src/HostInfo.ts @@ -16,9 +16,11 @@ export default class HostInfo { public plugins: Map, /** True if this host is currently connected to controller */ public connected: boolean = false, + /** IP this host last connected from */ + public remoteAddress: string = "", /** Value of host.public_address configured for this host */ public publicAddress: string = "", - /** Unix timestamp in seconds host token must be issued afterto be valid */ + /** Unix timestamp in seconds host token must be issued after to be valid */ public tokenValidAfter: number = 0, /** Millisecond Unix timestamp this entry was last updated at */ public updatedAt: number = 0, @@ -32,6 +34,7 @@ export default class HostInfo { "version": Type.String(), "plugins": Type.Record(Type.String(), Type.String()), "connected": Type.Boolean(), + "remote_address": Type.String(), "public_address": Type.String(), "token_valid_after": Type.Number(), "updated_at": Type.Number(), @@ -45,6 +48,7 @@ export default class HostInfo { json.version, new Map(Object.entries(json.plugins)), json.connected, + json.remote_address, json.public_address, json.token_valid_after, json.updated_at, @@ -59,6 +63,7 @@ export default class HostInfo { version: this.version, plugins: Object.fromEntries(this.plugins), connected: this.connected, + remote_address: this.remoteAddress, public_address: this.publicAddress, token_valid_after: this.tokenValidAfter, updated_at: this.updatedAt, @@ -72,6 +77,7 @@ export default class HostInfo { this.name, this.id, this.connected, + this.remoteAddress, this.publicAddress, this.tokenValidAfter, this.updatedAt, diff --git a/packages/controller/src/WsServer.ts b/packages/controller/src/WsServer.ts index 4ebb257f..50c37d9c 100644 --- a/packages/controller/src/WsServer.ts +++ b/packages/controller/src/WsServer.ts @@ -284,7 +284,7 @@ ${err.stack}` ); } - connection = new HostConnection(data, connector, this.controller); + connection = new HostConnection(data, connector, this.controller, this.remoteAddr(req)); connector.on("close", () => { if (this.hostConnections.get(data.id) === connection) { this.hostConnections.delete(data.id); diff --git a/packages/lib/src/data/messages_host.ts b/packages/lib/src/data/messages_host.ts index 5f2cf88a..df8d719f 100644 --- a/packages/lib/src/data/messages_host.ts +++ b/packages/lib/src/data/messages_host.ts @@ -64,8 +64,9 @@ export class HostDetails { public name: string, public id: number, public connected: boolean, - public publicAddress?: string, - public tokenValidAfter?: number, + public remoteAddress = "", + public publicAddress: string = "", + public tokenValidAfter: number = 0, /** Millisecond Unix timestamp this entry was last updated at */ public updatedAt = 0, public isDeleted = false, @@ -76,6 +77,7 @@ export class HostDetails { "name": Type.String(), "id": Type.Integer(), "connected": Type.Boolean(), + "remoteAddress": Type.Optional(Type.String()), "publicAddress": Type.Optional(Type.String()), "tokenValidAfter": Type.Optional(Type.Number()), "updatedAt": Type.Optional(Type.Number()), @@ -88,6 +90,7 @@ export class HostDetails { json.name, json.id, json.connected, + json.remoteAddress, json.publicAddress, json.tokenValidAfter, json.updatedAt, diff --git a/packages/web_ui/src/components/HostViewPage.tsx b/packages/web_ui/src/components/HostViewPage.tsx index 7963a619..efe128f6 100644 --- a/packages/web_ui/src/components/HostViewPage.tsx +++ b/packages/web_ui/src/components/HostViewPage.tsx @@ -83,6 +83,7 @@ export default function HostViewPage() { {system?.kernel} {system?.machine} {system?.hostname} + {host.remoteAddress} {system?.cpuModel}