Implemented starting and stopping listeners from the ImGui client.
This commit is contained in:
@@ -1,77 +0,0 @@
|
||||
import whisky
|
||||
import times, tables
|
||||
import ../views/[sessions, listeners, console, eventlog]
|
||||
import ../../common/[types, utils, event]
|
||||
export recvEvent
|
||||
|
||||
#[
|
||||
Server -> Client
|
||||
]#
|
||||
|
||||
|
||||
|
||||
|
||||
# proc getMessageType*(message: Message): EventType =
|
||||
# var unpacker = Unpacker.init(message.data)
|
||||
# return cast[EventType](unpacker.getUint8())
|
||||
|
||||
# proc receiveAgentPayload*(message: Message): seq[byte] =
|
||||
# var unpacker = Unpacker.init(message.data)
|
||||
|
||||
# discard unpacker.getUint8()
|
||||
# return string.toBytes(unpacker.getDataWithLengthPrefix())
|
||||
|
||||
# proc receiveAgentConnection*(message: Message, sessions: ptr SessionsTableComponent) =
|
||||
# var unpacker = Unpacker.init(message.data)
|
||||
|
||||
# discard unpacker.getUint8()
|
||||
# let agent = Agent(
|
||||
# agentId: Uuid.toString(unpacker.getUint32()),
|
||||
# listenerId: Uuid.toString(unpacker.getUint32()),
|
||||
# username: unpacker.getDataWithLengthPrefix(),
|
||||
# hostname: unpacker.getDataWithLengthPrefix(),
|
||||
# domain: unpacker.getDataWithLengthPrefix(),
|
||||
# ip: unpacker.getDataWithLengthPrefix(),
|
||||
# os: unpacker.getDataWithLengthPrefix(),
|
||||
# process: unpacker.getDataWithLengthPrefix(),
|
||||
# pid: int(unpacker.getUint32()),
|
||||
# elevated: unpacker.getUint8() != 0,
|
||||
# sleep: int(unpacker.getUint32()),
|
||||
# tasks: @[],
|
||||
# firstCheckin: cast[int64](unpacker.getUint32()).fromUnix().utc(),
|
||||
# latestCheckin: cast[int64](unpacker.getUint32()).fromUnix().utc(),
|
||||
# )
|
||||
|
||||
# sessions.agents.add(agent)
|
||||
|
||||
# proc receiveAgentCheckin*(message: Message, sessions: ptr SessionsTableComponent)=
|
||||
# var unpacker = Unpacker.init(message.data)
|
||||
|
||||
# discard unpacker.getUint8()
|
||||
# let agentId = Uuid.toString(unpacker.getUint32())
|
||||
# let timestamp = cast[int64](unpacker.getUint32())
|
||||
|
||||
# # TODO: Update checkin
|
||||
|
||||
# proc receiveConsoleItem*(message: Message, consoles: ptr Table[string, ConsoleComponent]) =
|
||||
# var unpacker = Unpacker.init(message.data)
|
||||
|
||||
# discard unpacker.getUint8()
|
||||
# let
|
||||
# agentId = Uuid.toString(unpacker.getUint32())
|
||||
# logType = cast[LogType](unpacker.getUint8())
|
||||
# timestamp = cast[int64](unpacker.getUint32())
|
||||
# message = unpacker.getDataWithLengthPrefix()
|
||||
|
||||
# consoles[][agentId].addItem(logType, message, timestamp)
|
||||
|
||||
# proc receiveEventlogItem*(message: Message, eventlog: ptr EventlogComponent) =
|
||||
# var unpacker = Unpacker.init(message.data)
|
||||
|
||||
# discard unpacker.getUint8()
|
||||
# let
|
||||
# logType = cast[LogType](unpacker.getUint8())
|
||||
# timestamp = cast[int64](unpacker.getUint32())
|
||||
# message = unpacker.getDataWithLengthPrefix()
|
||||
|
||||
# eventlog[].addItem(logType, message, timestamp)
|
||||
@@ -3,7 +3,7 @@ import tables, strutils, json, parsetoml
|
||||
import ./utils/appImGui
|
||||
import ./views/[dockspace, sessions, listeners, eventlog, console]
|
||||
import ../common/[types, utils]
|
||||
import ./event/[send, recv]
|
||||
import ./websocket
|
||||
|
||||
import sugar
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import imguin/[cimgui, glfw_opengl, simple]
|
||||
import ../utils/appImGui
|
||||
import ../../common/[types, utils]
|
||||
import ./modals/[startListener, generatePayload]
|
||||
import ../event/send
|
||||
import ../websocket
|
||||
import whisky
|
||||
|
||||
type
|
||||
@@ -76,15 +76,14 @@ proc draw*(component: ListenersTableComponent, showComponent: ptr bool, ws: WebS
|
||||
var multiSelectIO = igBeginMultiSelect(ImGuiMultiSelectFlags_ClearOnEscape.int32 or ImGuiMultiSelectFlags_BoxSelect1d.int32, component.selection[].Size, int32(component.listeners.len()))
|
||||
ImGuiSelectionBasicStorage_ApplyRequests(component.selection, multiSelectIO)
|
||||
|
||||
for row in 0 ..< component.listeners.len():
|
||||
for i, listener in component.listeners:
|
||||
|
||||
igTableNextRow(ImGuiTableRowFlags_None.int32, 0.0f)
|
||||
let listener = component.listeners[row]
|
||||
|
||||
if igTableSetColumnIndex(0):
|
||||
# Enable multi-select functionality
|
||||
igSetNextItemSelectionUserData(row)
|
||||
var isSelected = ImGuiSelectionBasicStorage_Contains(component.selection, cast[ImGuiID](row))
|
||||
igSetNextItemSelectionUserData(i)
|
||||
var isSelected = ImGuiSelectionBasicStorage_Contains(component.selection, cast[ImGuiID](i))
|
||||
discard igSelectable_Bool(listener.listenerId, isSelected, ImGuiSelectableFlags_SpanAllColumns.int32, vec2(0.0f, 0.0f))
|
||||
|
||||
if igTableSetColumnIndex(1):
|
||||
@@ -101,11 +100,11 @@ proc draw*(component: ListenersTableComponent, showComponent: ptr bool, ws: WebS
|
||||
if igMenuItem("Stop", nil, false, true):
|
||||
# Update agents table with only non-selected ones
|
||||
var newListeners: seq[UIListener] = @[]
|
||||
for i in 0 ..< component.listeners.len():
|
||||
for i, listener in component.listeners:
|
||||
if not ImGuiSelectionBasicStorage_Contains(component.selection, cast[ImGuiID](i)):
|
||||
newListeners.add(component.listeners[i])
|
||||
newListeners.add(listener)
|
||||
else:
|
||||
ws.sendStopListener(component.listeners[i].listenerId)
|
||||
ws.sendStopListener(listener.listenerId)
|
||||
|
||||
component.listeners = newListeners
|
||||
ImGuiSelectionBasicStorage_Clear(component.selection)
|
||||
|
||||
@@ -75,7 +75,6 @@ proc draw*(component: ListenerModalComponent): UIListener =
|
||||
igBeginDisabled(($(addr component.address[0]) == "") or (component.port <= 0))
|
||||
|
||||
if igButton("Start", vec2(availableSize.x * 0.5 - textSpacing * 0.5, 0.0f)):
|
||||
|
||||
result = UIListener(
|
||||
listenerId: generateUUID(),
|
||||
address: $(addr component.address[0]),
|
||||
|
||||
@@ -1,34 +1,29 @@
|
||||
import whisky
|
||||
import times, tables
|
||||
import ../views/[sessions, listeners, console, eventlog]
|
||||
import ../../common/[types, utils, serialize, event]
|
||||
export sendHeartbeat
|
||||
import times, tables, json
|
||||
import ./views/[sessions, listeners, console, eventlog]
|
||||
import ../common/[types, utils, serialize, event]
|
||||
export sendHeartbeat, recvEvent
|
||||
|
||||
#[
|
||||
Client -> Server
|
||||
]#
|
||||
proc sendStartListener*(ws: WebSocket, listener: UIListener) =
|
||||
var packer = Packer.init()
|
||||
|
||||
packer.add(cast[uint8](CLIENT_LISTENER_START))
|
||||
packer.add(string.toUUid(listener.listenerId))
|
||||
packer.addDataWithLengthPrefix(string.toBytes(listener.address))
|
||||
packer.add(cast[uint16](listener.port))
|
||||
packer.add(cast[uint8](listener.protocol))
|
||||
|
||||
let data = packer.pack()
|
||||
|
||||
ws.send(Bytes.toString(data), BinaryMessage)
|
||||
let event = Event(
|
||||
eventType: CLIENT_LISTENER_START,
|
||||
timestamp: now().toTime().toUnix(),
|
||||
data: %listener
|
||||
)
|
||||
ws.sendEvent(event)
|
||||
|
||||
proc sendStopListener*(ws: WebSocket, listenerId: string) =
|
||||
discard
|
||||
# var packer = Packer.init()
|
||||
|
||||
# packer.add(cast[uint8](CLIENT_LISTENER_STOP))
|
||||
# packer.add(string.toUuid(listenerId))
|
||||
# let data = packer.pack()
|
||||
|
||||
# ws.send(Bytes.toString(data), BinaryMessage)
|
||||
let event = Event(
|
||||
eventType: CLIENT_LISTENER_STOP,
|
||||
timestamp: now().toTime().toUnix(),
|
||||
data: %*{
|
||||
"listenerId": listenerId
|
||||
}
|
||||
)
|
||||
ws.sendEvent(event)
|
||||
|
||||
# proc sendAgentCommand*(ws: WebSocket, agentId: string, command: string) =
|
||||
# var packer = Packer.init()
|
||||
Reference in New Issue
Block a user