Added number of agents to listener list
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,6 @@
|
|||||||
# Ignore agents
|
# Ignore agents
|
||||||
agents/
|
agents/
|
||||||
|
*.db
|
||||||
|
|
||||||
# Nim
|
# Nim
|
||||||
nimcache/
|
nimcache/
|
||||||
|
|||||||
@@ -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) =
|
||||||
|
|
||||||
# Check if listener exists
|
# If no argument is passed via -n, list all agents, otherwise only display agents connected to a specific listener
|
||||||
if not cq.dbListenerExists(listener.toUpperAscii):
|
if listener == "":
|
||||||
cq.writeLine(fgRed, styleBright, fmt"[-] Listener {listener.toUpperAscii} does not exist.")
|
cq.drawTable(cq.dbGetAllAgents())
|
||||||
return
|
else:
|
||||||
|
# Check if listener exists
|
||||||
|
if not cq.dbListenerExists(listener.toUpperAscii):
|
||||||
|
cq.writeLine(fgRed, styleBright, fmt"[-] Listener {listener.toUpperAscii} does not exist.")
|
||||||
|
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}
|
||||||
|
|||||||
@@ -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":
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
Reference in New Issue
Block a user