From 9de4ac48389887e15f792bf9e3f764e7521a7801 Mon Sep 17 00:00:00 2001 From: Jakob Friedl <71284620+jakobfriedl@users.noreply.github.com> Date: Fri, 26 Sep 2025 18:27:38 +0200 Subject: [PATCH] Small refactors --- src/client/layout.ini | 188 -------------------- src/client/main.nim | 17 +- src/client/views/listeners.nim | 2 +- src/client/views/modals/generatePayload.nim | 2 +- src/client/views/sessions.nim | 15 +- 5 files changed, 28 insertions(+), 196 deletions(-) delete mode 100644 src/client/layout.ini diff --git a/src/client/layout.ini b/src/client/layout.ini deleted file mode 100644 index afcf481..0000000 --- a/src/client/layout.ini +++ /dev/null @@ -1,188 +0,0 @@ -[Window][Sessions [Table View]] -Pos=10,43 -Size=1188,394 -Collapsed=0 -DockId=0x00000003,0 - -[Window][Listeners] -Pos=10,439 -Size=1888,550 -Collapsed=0 -DockId=0x00000002,0 - -[Window][Eventlog] -Pos=1200,43 -Size=698,394 -Collapsed=0 -DockId=0x00000004,0 - -[Window][Dear ImGui Demo] -Collapsed=0 -DockId=0x00000004 - -[Window][Dockspace] -Pos=0,0 -Size=1908,999 -Collapsed=0 - -[Window][[7E248CBA] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,0 - -[Window][[7BE69219] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,2 - -[Window][[CD44669B] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,1 - -[Window][[F300DB27] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,3 - -[Window][[AB3464CE] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002 - -[Window][[3FC9903D] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,3 - -[Window][[6CD04F2C] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,1 - -[Window][[4E93619C] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,8 - -[Window][[0C56BE7D] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,7 - -[Window][[37C08F6C] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,4 - -[Window][[BCC8B616] jakob@AURA] -Pos=10,315 -Size=1004,475 -Collapsed=0 -DockId=0x00000002,0 - -[Window][Debug##Default] -Pos=60,60 -Size=400,400 -Collapsed=0 - -[Window][[9592878D] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,1 - -[Window][[8F8DC95F] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,0 - -[Window][[E05185F6] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,2 - -[Window][[022E62E0] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002 - -[Window][[F5CE46E3] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,6 - -[Window][[37DAA990] jakob@AURA] -Pos=10,439 -Size=1888,550 -Collapsed=0 -DockId=0x00000002,1 - -[Window][[824B6EC7] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002 - -[Window][[386BFA92] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,5 - -[Window][[209155FC] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,1 - -[Window][[2498CB04] jakob@AURA] -Pos=10,514 -Size=1888,475 -Collapsed=0 -DockId=0x00000002,0 - -[Window][[0EBC9C82] jakob@AURA] -Pos=10,439 -Size=1888,550 -Collapsed=0 -DockId=0x00000002,2 - -[Table][0x32886A44,9] -Column 0 Weight=0.9882 Visible=1 -Column 1 Weight=1.1970 Visible=1 -Column 2 Weight=0.7725 Visible=1 -Column 3 Weight=0.6681 Visible=1 -Column 4 Weight=1.3658 Visible=0 -Column 5 Weight=0.9604 Visible=1 -Column 6 Weight=1.2944 Visible=1 -Column 7 Weight=0.4175 Visible=1 -Column 8 Weight=1.3361 Visible=1 - -[Table][0x064A67CC,4] -Column 0 Weight=1.0000 -Column 1 Weight=1.0000 -Column 2 Weight=1.0000 -Column 3 Weight=1.0000 - -[Docking][Data] -DockSpace ID=0x85940918 Window=0x260A4489 Pos=10,43 Size=1888,946 Split=Y - DockNode ID=0x00000001 Parent=0x85940918 SizeRef=1024,394 Split=X - DockNode ID=0x00000003 Parent=0x00000001 SizeRef=1188,159 CentralNode=1 Selected=0x61E02D75 - DockNode ID=0x00000004 Parent=0x00000001 SizeRef=698,159 Selected=0x0FA43D88 - DockNode ID=0x00000002 Parent=0x85940918 SizeRef=1024,550 Selected=0xE5DB7127 - diff --git a/src/client/main.nim b/src/client/main.nim index f392480..765b000 100644 --- a/src/client/main.nim +++ b/src/client/main.nim @@ -64,8 +64,8 @@ proc main() = # Receive and parse websocket response message let event = recvEvent(ws.receiveMessage().get()) case event.eventType: - # of CLIENT_PROFILE: - # profile = parsetoml.parseString(event.data["profile"].getStr()) + of CLIENT_PROFILE: + profile = parsetoml.parseString(event.data["profile"].getStr()) of CLIENT_LISTENER_ADD: let listener = event.data.to(UIListener) @@ -100,10 +100,19 @@ proc main() = discard of CLIENT_CONSOLE_ITEM: - consoles[event.data["agentId"].getStr()].addItem(cast[LogType](event.data["logType"].getInt()), event.data["message"].getStr(), event.timestamp) + let agentId = event.data["agentId"].getStr() + consoles[agentId].addItem( + cast[LogType](event.data["logType"].getInt()), + event.data["message"].getStr(), + event.timestamp + ) of CLIENT_EVENTLOG_ITEM: - eventlog.addItem(cast[LogType](event.data["logType"].getInt()), event.data["message"].getStr(), event.timestamp) + eventlog.addItem( + cast[LogType](event.data["logType"].getInt()), + event.data["message"].getStr(), + event.timestamp + ) else: discard diff --git a/src/client/views/listeners.nim b/src/client/views/listeners.nim index 7f3149a..b180ca6 100644 --- a/src/client/views/listeners.nim +++ b/src/client/views/listeners.nim @@ -12,7 +12,7 @@ type listeners*: seq[UIListener] selection: ptr ImGuiSelectionBasicStorage startListenerModal: ListenerModalComponent - generatePayloadModal: AgentModalComponent + generatePayloadModal*: AgentModalComponent proc ListenersTable*(title: string): ListenersTableComponent = result = new ListenersTableComponent diff --git a/src/client/views/modals/generatePayload.nim b/src/client/views/modals/generatePayload.nim index 294e291..6191188 100644 --- a/src/client/views/modals/generatePayload.nim +++ b/src/client/views/modals/generatePayload.nim @@ -1,7 +1,7 @@ import strutils, sequtils import imguin/[cimgui, glfw_opengl, simple] import ../../utils/[appImGui, colors] -import ../../../common/[types, utils] +import ../../../common/[types, profile, utils] import ../widgets/dualListSelection type diff --git a/src/client/views/sessions.nim b/src/client/views/sessions.nim index 8fa2a1c..b69cf2e 100644 --- a/src/client/views/sessions.nim +++ b/src/client/views/sessions.nim @@ -2,7 +2,7 @@ import times, tables, strformat, strutils import imguin/[cimgui, glfw_opengl, simple] import ./console -import ../utils/appImGui +import ../utils/[appImGui, colors] import ../../common/[types, utils] type @@ -25,6 +25,7 @@ proc interact(component: SessionsTableComponent) = # Open a new console for each selected agent session var it: pointer = nil var row: ImGuiID + while ImGuiSelectionBasicStorage_GetNextSelectedItem(component.selection, addr it, addr row): let agent = component.agents[cast[int](row)] @@ -35,6 +36,8 @@ proc interact(component: SessionsTableComponent) = # Focus the existing console window else: igSetWindowFocus_Str(fmt"[{agent.agentId}] {agent.username}@{agent.hostname}") + + component.selection.ImGuiSelectionBasicStorage_Clear() proc draw*(component: SessionsTableComponent, showComponent: ptr bool) = igBegin(component.title, showComponent, 0) @@ -110,7 +113,11 @@ proc draw*(component: SessionsTableComponent, showComponent: ptr bool) = let seconds = totalSeconds mod 60 let timeText = dateTime(2000, mJan, 1, hours.int, minutes.int, seconds.int).format("HH:mm:ss") - igText(fmt"{timeText} ago") + + if totalSeconds > agent.sleep: + igTextColored(GRAY, fmt"{timeText} ago") + else: + igText(fmt"{timeText} ago") # Handle right-click context menu # Right-clicking the table header to hide/show columns or reset the layout is only possible when no sessions are selected @@ -136,4 +143,8 @@ proc draw*(component: SessionsTableComponent, showComponent: ptr bool) = multiSelectIO = igEndMultiSelect() ImGuiSelectionBasicStorage_ApplyRequests(component.selection, multiSelectIO) + # Auto-scroll to bottom + if igGetScrollY() >= igGetScrollMaxY(): + igSetScrollHereY(1.0f) + igEndTable()