Added number of agents to listener list
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,6 @@
|
||||
# Ignore agents
|
||||
agents/
|
||||
|
||||
*.db
|
||||
|
||||
# Nim
|
||||
nimcache/
|
||||
|
||||
@@ -24,19 +24,18 @@ Options:
|
||||
-h, --help""")
|
||||
|
||||
# List agents
|
||||
proc agentList*(cq: Conquest) =
|
||||
let agents = cq.dbGetAllAgents()
|
||||
cq.drawTable(agents)
|
||||
|
||||
proc agentList*(cq: Conquest, listener: string) =
|
||||
|
||||
# Check if listener exists
|
||||
if not cq.dbListenerExists(listener.toUpperAscii):
|
||||
cq.writeLine(fgRed, styleBright, fmt"[-] Listener {listener.toUpperAscii} does not exist.")
|
||||
return
|
||||
# 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
|
||||
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(agents)
|
||||
cq.drawTable(cq.dbGetAllAgentsByListener(listener.toUpperAscii))
|
||||
|
||||
# Display agent properties and details
|
||||
proc agentInfo*(cq: Conquest, name: string) =
|
||||
@@ -47,7 +46,7 @@ proc agentInfo*(cq: Conquest, name: string) =
|
||||
|
||||
let agent = cq.agents[name.toUpperAscii]
|
||||
|
||||
# TODO: Improve formating
|
||||
# TODO: Improve formatting
|
||||
cq.writeLine(fmt"""
|
||||
Agent name (UUID): {agent.name}
|
||||
Connected to listener: {agent.listener}
|
||||
|
||||
@@ -32,8 +32,7 @@ var parser = newParser:
|
||||
|
||||
command("list"):
|
||||
help("List all agents.")
|
||||
option("-n", "-name", 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>)
|
||||
option("-l", "-listener", help="Name of the listener.")
|
||||
|
||||
command("info"):
|
||||
help("Display details for a specific agent.")
|
||||
@@ -86,11 +85,8 @@ proc handleConsoleCommand*(cq: Conquest, args: varargs[string]) =
|
||||
|
||||
of "agent":
|
||||
case opts.agent.get.command
|
||||
of "list":
|
||||
if opts.agent.get.list.get.name == "":
|
||||
cq.agentList()
|
||||
else:
|
||||
cq.agentList(opts.agent.get.list.get.name)
|
||||
of "list":
|
||||
cq.agentList(opts.agent.get.list.get.listener)
|
||||
of "info":
|
||||
cq.agentInfo(opts.agent.get.info.get.name)
|
||||
of "kill":
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import re, strutils, strformat, terminal
|
||||
import re, strutils, strformat, terminal, tables, sequtils
|
||||
|
||||
import ./types
|
||||
|
||||
@@ -61,8 +61,10 @@ proc drawTable*(cq: Conquest, listeners: seq[Listener]) =
|
||||
cq.writeLine(border(midLeft, midMid, midRight, widths))
|
||||
|
||||
for l in listeners:
|
||||
# TODO: Add number of agents connected to the listener
|
||||
let row = @[l.name, l.address, $l.port, $l.protocol, "X"]
|
||||
# Get number of agents connected to the listener
|
||||
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(border(botLeft, botMid, botRight, widths))
|
||||
|
||||
Reference in New Issue
Block a user