Started implementing profile system.
This commit is contained in:
37
data/profile.toml
Normal file
37
data/profile.toml
Normal 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"
|
||||
@@ -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="
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,4 +4,4 @@ import ../modules/manager
|
||||
# Conquest framework entry point
|
||||
when isMainModule:
|
||||
loadModules()
|
||||
startServer()
|
||||
import cligen; dispatch startServer
|
||||
Reference in New Issue
Block a user