Compare commits

...

10 Commits

Author SHA1 Message Date
venus
df46501731 going to bed, updated the headers file to consolidate data and config dir, for now. Also began working on parsing user input. need to check out click 2026-04-14 03:46:19 -05:00
venus
be093ed3b3 updated config logic to read from one file 2026-04-14 03:36:14 -05:00
venus
3007d07d62 config testing 2026-04-07 02:06:20 -05:00
venus
97332f7d01 hid config file 2026-04-07 02:04:55 -05:00
venus
09b4947e6e added config class to validate config entries 2026-04-07 02:04:00 -05:00
venus
f0d2f18364 config parsing works with persistance 2026-04-06 15:19:11 -05:00
venus
a74553bd88 added state options as an object with dict storing to disk 2026-04-06 00:26:43 -05:00
venus
b208cc2ddb config works 2026-04-05 23:31:32 -05:00
venus
7e88b51db6 initialized as project working now 2026-04-05 23:21:33 -05:00
venus
a70694dbd5 initialized as project 2026-04-05 23:00:30 -05:00
9 changed files with 124 additions and 26 deletions

4
.gitignore vendored
View File

@@ -8,3 +8,7 @@ wheels/
# Virtual environments
.venv
#development files
state.json
config.json

View File

@@ -1,8 +1,6 @@
#config
#file with global options
#key = "val"
[CTF-DATA]
current-challenge = "testChal"
current-comp = "testComp"
key-format = "SKY-aaaa-0000"
#comments ignored
[Competition]
competition = "mycomp"
catagory = "somecat"
challenge = "somechal"
[Enviroment]
data_dir = "/home/venus/code/ctf/"

View File

@@ -4,4 +4,19 @@ version = "0.1.0"
description = "An AI enhanced CTF toolchain"
readme = "README.md"
requires-python = ">=3.14"
dependencies = []
dependencies = [
"platformdirs>=4.9.4",
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project.scripts]
ctf = "ctf.main:main"
[tool.hatch.build.targets.wheel]
packages = ["src/ctf"]
[tool.pyright]
extraPaths = ["src"]

View File

@@ -1,9 +0,0 @@
# functions for commands needed
# src/commands.py
import os
# Read variables
# Initialize a challenge
## Copy files into directory
## add section to log

22
src/ctf/commands.py Normal file
View File

@@ -0,0 +1,22 @@
# functions for commands needed
# src/commands.py
import os
from ctf.utils import state
from pathlib import path
def test():
print("hello from test")
def Set_Challenge(comp: str, chal: str, setDirectory: bool):
# set the current challenge and competition from input
if state.current_comp != comp:
state.current_comp=comp
state.comp_dir=pathlib
# TODO archive the old competitions
if state.current_chal != chal:
state.current_chal=chal
print("challenge already set")
# TODO archive the old challenges
# TODO set the directory to challenge directory, with ignore option

34
src/ctf/main.py Normal file
View File

@@ -0,0 +1,34 @@
# src/main.py
# Parses and calls commands
import argparse
from ctf.utils import state
def setArguments():
parser = argparse.ArgumentParser( #type:ignore
prog="ctf",
description="A collection of cli tools to improve your ctf workflow",
epilog="")
parser.add_argument('action') # positional argument, action to be taken
parser.add_argument('-c', '--count') # option that takes a value
parser.add_argument('-v', '--verbose', action='store_true') # on/off flag
args = parser.parse_args()
return args
def main():
state.info = "me"
# Parse arguments
# Current Ctf
# Current Challenge
# Validate args
# Call library functiions
# Set Ctf
args = setArguments()
if args.action == set:
print(f"setting ctf to{args.ctf}")
if __name__ == "__main__":
main()

42
src/ctf/utils.py Normal file
View File

@@ -0,0 +1,42 @@
# src/ctf/utils.py
# basic utilities
import tomllib
import json
import toml
from pathlib import Path
from platformdirs import user_config_dir
# Parse config file
class StateManager:
_path : Path
_data: dict
def __init__(self):
# Assume data directory exists on install and defined in config
# TODO check datadir valid
object.__setattr__(self, "_path", "user_config_dir/config.json") # set self._path to data_dir safely
object.__setattr__(self, "_data", self._load()) # load objects into self
def _load(self):
if self._path.exists():
with open(self._path, "r") as f:
return toml.load(f)
return{}
def __getattr__(self, name):
# use state.challenge to return value for challenge from dictionary
return self._data.get(name)
def __setattr__(self, name, value):
# use state.challenge = "run" to set challenge and run to dictionary
# writes the whole dict to disk
self._data[name] = value
with open(self._path, "w",) as f:
json.dump(self._data, f, indent=4)
def __repr__(self):
return f"StateManager({self.__dict__})"
state = StateManager()

View File

@@ -1,8 +0,0 @@
# src/main.py
# Parses and calls commands
def main():
print("Hello from ctf!")
if __name__ == "__main__":
main()