Compare commits

...
10 Commits
9 changed files with 124 additions and 26 deletions
+4
View File
@@ -8,3 +8,7 @@ wheels/
# Virtual environments
.venv
#development files
state.json
config.json
+6 -8
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/"
+16 -1
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"]
-9
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
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
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
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()
-8
View File
@@ -1,8 +0,0 @@
# src/main.py
# Parses and calls commands
def main():
print("Hello from ctf!")
if __name__ == "__main__":
main()