Started implementing profile system.

This commit is contained in:
Jakob Friedl
2025-08-13 19:32:51 +02:00
parent b7622dd72f
commit 415cd7ebf8
6 changed files with 75 additions and 19 deletions

View File

@@ -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="

View File

@@ -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

View File

@@ -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:

View File

@@ -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

View File

@@ -4,4 +4,4 @@ import ../modules/manager
# Conquest framework entry point
when isMainModule:
loadModules()
startServer()
import cligen; dispatch startServer