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

37
data/profile.toml Normal file
View File

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

View File

@@ -1,9 +1,9 @@
# Agent configuration # Agent configuration
-d:ListenerUuid="D0981BF3" -d:ListenerUuid="58A66E35"
-d:Octet1="172" -d:Octet1="127"
-d:Octet2="29" -d:Octet2="0"
-d:Octet3="177" -d:Octet3="0"
-d:Octet4="43" -d:Octet4="1"
-d:ListenerPort=6666 -d:ListenerPort=5555
-d:SleepDelay=10 -d:SleepDelay=5
-d:ServerPublicKey="mi9o0kPu1ZSbuYfnG5FmDUMAvEXEvp11OW9CQLCyL1U=" -d:ServerPublicKey="OzczGQndMRzmaVcJo5USBBSrk76FsNlU8SNzCGbyVgo="

View File

@@ -2,6 +2,7 @@ import prompt
import tables import tables
import times import times
import streams import streams
import parsetoml
# Custom Binary Task structure # Custom Binary Task structure
const const
@@ -149,18 +150,25 @@ type
Protocol* = enum Protocol* = enum
HTTP = "http" HTTP = "http"
Listener* = ref object Listener* = ref object of RootObj
listenerId*: string listenerId*: string
address*: string address*: string
port*: int port*: int
protocol*: Protocol protocol*: Protocol
HttpListener* = ref object of Listener
register_endpoint*: string
get_endpoint*: string
post_endpoint*: string
# Server context structure # Server context structure
type type
KeyPair* = object KeyPair* = object
privateKey*: Key privateKey*: Key
publicKey*: Key publicKey*: Key
Profile* = TomlTableRef
Conquest* = ref object Conquest* = ref object
prompt*: Prompt prompt*: Prompt
dbPath*: string dbPath*: string
@@ -168,6 +176,7 @@ type
agents*: Table[string, Agent] agents*: Table[string, Agent]
interactAgent*: Agent interactAgent*: Agent
keyPair*: KeyPair keyPair*: KeyPair
profile*: Profile
# Agent config # Agent config
type type

View File

@@ -87,7 +87,6 @@ proc handleResult*(resultData: seq[byte]) =
of STATUS_IN_PROGRESS: of STATUS_IN_PROGRESS:
discard discard
case cast[ResultType](taskResult.resultType): case cast[ResultType](taskResult.resultType):
of RESULT_STRING: of RESULT_STRING:
if int(taskResult.length) > 0: 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 strutils, strformat, times, system, tables
import ./[agent, listener] import ./[agent, listener]
@@ -127,29 +127,40 @@ proc header(cq: Conquest) =
cq.writeLine("".repeat(21)) cq.writeLine("".repeat(21))
cq.writeLine("") cq.writeLine("")
# TODO: Add profile support instead of hardcoded paths, etc. proc init*(T: type Conquest, profile: Profile): Conquest =
proc initConquest*(): Conquest =
var cq = new Conquest var cq = new Conquest
var prompt = Prompt.init() var prompt = Prompt.init()
cq.prompt = prompt cq.prompt = prompt
cq.dbPath = "../data/conquest.db"
cq.listeners = initTable[string, Listener]() cq.listeners = initTable[string, Listener]()
cq.agents = initTable[string, Agent]() cq.agents = initTable[string, Agent]()
cq.interactAgent = nil 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 return cq
proc startServer*() = proc startServer*(profile: string) =
# Handle CTRL+C, # Handle CTRL+C,
proc exit() {.noconv.} = proc exit() {.noconv.} =
echo "Received CTRL+C. Type \"exit\" to close the application.\n" echo "Received CTRL+C. Type \"exit\" to close the application.\n"
setControlCHook(exit) 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 # Initialize framework
try: try:
cq = initConquest() cq = Conquest.init(profile)
except CatchableError as err: except CatchableError as err:
echo err.msg echo err.msg

View File

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