This commit is contained in:
Logan
2026-04-06 00:22:03 -04:00
parent 2f0597c81b
commit 636a847ee1
9 changed files with 133 additions and 21 deletions
@@ -8,10 +8,15 @@ class C2Client:
def __init__(self):
self.base = settings.c2_url.rstrip("/")
def _headers(self) -> dict:
if settings.c2_service_key:
return {"Authorization": f"Bearer {settings.c2_service_key}"}
return {}
async def get_nodes(self) -> list:
try:
async with httpx.AsyncClient(timeout=10) as client:
r = await client.get(f"{self.base}/nodes")
r = await client.get(f"{self.base}/nodes", headers=self._headers())
r.raise_for_status()
return r.json()
except Exception as e:
@@ -21,19 +26,30 @@ class C2Client:
async def get_systems(self) -> list:
try:
async with httpx.AsyncClient(timeout=10) as client:
r = await client.get(f"{self.base}/systems")
r = await client.get(f"{self.base}/systems", headers=self._headers())
r.raise_for_status()
return r.json()
except Exception as e:
logger.error(f"C2 get_systems failed: {e}")
return []
async def get_tokens(self) -> list:
try:
async with httpx.AsyncClient(timeout=10) as client:
r = await client.get(f"{self.base}/tokens", headers=self._headers())
r.raise_for_status()
return r.json()
except Exception as e:
logger.error(f"C2 get_tokens failed: {e}")
return []
async def send_command(self, node_id: str, payload: dict) -> bool:
try:
async with httpx.AsyncClient(timeout=10) as client:
r = await client.post(
f"{self.base}/nodes/{node_id}/command",
json=payload,
headers=self._headers(),
)
r.raise_for_status()
return True