2022-09-06 15:07:12 +02:00
|
|
|
import { Terminal } from "../../Terminal";
|
2021-09-16 01:50:44 +02:00
|
|
|
import { BaseServer } from "../../Server/BaseServer";
|
|
|
|
import { getServerOnNetwork } from "../../Server/ServerHelpers";
|
|
|
|
|
2022-09-06 15:07:12 +02:00
|
|
|
export function scan(args: (string | number | boolean)[], currServ: BaseServer): void {
|
2021-09-16 01:50:44 +02:00
|
|
|
if (args.length !== 0) {
|
2022-09-06 15:07:12 +02:00
|
|
|
Terminal.error("Incorrect usage of scan command. Usage: scan");
|
2021-09-16 01:50:44 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Displays available network connections using TCP
|
|
|
|
const servers = currServ.serversOnNetwork.map((_, i) => {
|
|
|
|
const server = getServerOnNetwork(currServ, i);
|
|
|
|
if (server === null) throw new Error("Server should not be null");
|
|
|
|
return {
|
|
|
|
hostname: server.hostname,
|
|
|
|
ip: server.ip,
|
|
|
|
hasRoot: server.hasAdminRights ? "Y" : "N",
|
|
|
|
};
|
|
|
|
});
|
|
|
|
servers.unshift({
|
|
|
|
hostname: "Hostname",
|
|
|
|
ip: "IP",
|
|
|
|
hasRoot: "Root Access",
|
|
|
|
});
|
|
|
|
const maxHostname = Math.max(...servers.map((s) => s.hostname.length));
|
|
|
|
const maxIP = Math.max(...servers.map((s) => s.ip.length));
|
|
|
|
for (const server of servers) {
|
|
|
|
if (!server) continue;
|
|
|
|
let entry = server.hostname;
|
|
|
|
entry += " ".repeat(maxHostname - server.hostname.length + 1);
|
|
|
|
entry += server.ip;
|
|
|
|
entry += " ".repeat(maxIP - server.ip.length + 1);
|
|
|
|
entry += server.hasRoot;
|
2022-09-06 15:07:12 +02:00
|
|
|
Terminal.print(entry);
|
2021-09-16 01:50:44 +02:00
|
|
|
}
|
|
|
|
}
|