Added number of agents to listener list

This commit is contained in:
Jakob Friedl
2025-05-15 15:24:46 +02:00
parent 9d652df4e3
commit 56f8994069
4 changed files with 19 additions and 22 deletions

2
.gitignore vendored
View File

@@ -1,6 +1,6 @@
# Ignore agents # Ignore agents
agents/ agents/
*.db
# Nim # Nim
nimcache/ nimcache/

View File

@@ -24,19 +24,18 @@ Options:
-h, --help""") -h, --help""")
# List agents # List agents
proc agentList*(cq: Conquest) =
let agents = cq.dbGetAllAgents()
cq.drawTable(agents)
proc agentList*(cq: Conquest, listener: string) = proc agentList*(cq: Conquest, listener: string) =
# If no argument is passed via -n, list all agents, otherwise only display agents connected to a specific listener
if listener == "":
cq.drawTable(cq.dbGetAllAgents())
else:
# Check if listener exists # Check if listener exists
if not cq.dbListenerExists(listener.toUpperAscii): if not cq.dbListenerExists(listener.toUpperAscii):
cq.writeLine(fgRed, styleBright, fmt"[-] Listener {listener.toUpperAscii} does not exist.") cq.writeLine(fgRed, styleBright, fmt"[-] Listener {listener.toUpperAscii} does not exist.")
return return
let agents = cq.dbGetAllAgentsByListener(listener.toUpperAscii) cq.drawTable(cq.dbGetAllAgentsByListener(listener.toUpperAscii))
cq.drawTable(agents)
# Display agent properties and details # Display agent properties and details
proc agentInfo*(cq: Conquest, name: string) = proc agentInfo*(cq: Conquest, name: string) =
@@ -47,7 +46,7 @@ proc agentInfo*(cq: Conquest, name: string) =
let agent = cq.agents[name.toUpperAscii] let agent = cq.agents[name.toUpperAscii]
# TODO: Improve formating # TODO: Improve formatting
cq.writeLine(fmt""" cq.writeLine(fmt"""
Agent name (UUID): {agent.name} Agent name (UUID): {agent.name}
Connected to listener: {agent.listener} Connected to listener: {agent.listener}

View File

@@ -32,8 +32,7 @@ var parser = newParser:
command("list"): command("list"):
help("List all agents.") help("List all agents.")
option("-n", "-name", help="Name of the listener.") option("-l", "-listener", help="Name of the listener.")
# TODO: Add a flag that allows the user to only list agents that are connected to a specific listener (-n <uuid>)
command("info"): command("info"):
help("Display details for a specific agent.") help("Display details for a specific agent.")
@@ -87,10 +86,7 @@ proc handleConsoleCommand*(cq: Conquest, args: varargs[string]) =
of "agent": of "agent":
case opts.agent.get.command case opts.agent.get.command
of "list": of "list":
if opts.agent.get.list.get.name == "": cq.agentList(opts.agent.get.list.get.listener)
cq.agentList()
else:
cq.agentList(opts.agent.get.list.get.name)
of "info": of "info":
cq.agentInfo(opts.agent.get.info.get.name) cq.agentInfo(opts.agent.get.info.get.name)
of "kill": of "kill":

View File

@@ -1,4 +1,4 @@
import re, strutils, strformat, terminal import re, strutils, strformat, terminal, tables, sequtils
import ./types import ./types
@@ -61,8 +61,10 @@ proc drawTable*(cq: Conquest, listeners: seq[Listener]) =
cq.writeLine(border(midLeft, midMid, midRight, widths)) cq.writeLine(border(midLeft, midMid, midRight, widths))
for l in listeners: for l in listeners:
# TODO: Add number of agents connected to the listener # Get number of agents connected to the listener
let row = @[l.name, l.address, $l.port, $l.protocol, "X"] let connectedAgents = cq.agents.values.countIt(it.listener == l.name)
let row = @[l.name, l.address, $l.port, $l.protocol, $connectedAgents]
cq.writeLine(row(row, widths)) cq.writeLine(row(row, widths))
cq.writeLine(border(botLeft, botMid, botRight, widths)) cq.writeLine(border(botLeft, botMid, botRight, widths))