Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ WORKDIR /app/src
EXPOSE 8000
EXPOSE 8081
# Run both main app and admin app
CMD ["sh", "-c", "gunicorn -w 4 -k uvicorn.workers.UvicornWorker pwncore:app --bind 0.0.0.0:8000 --log-level debug & uvicorn pwncore.admin_app:admin_app --host 0.0.0.0 --port 8081 & wait"]
CMD ["sh", "-c", "gunicorn -w 4 -k uvicorn.workers.UvicornWorker pwncore:app --bind 0.0.0.0:8000 --log-level debug"]
1 change: 0 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ services:
dockerfile: Dockerfile
ports:
- ${PORT}:8000
- ${PORT_ADMIN}:8081
environment:
- DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
- WORKERS=${WORKERS}
Expand Down
14 changes: 1 addition & 13 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ gunicorn = "^23.0.0"
bcrypt = ">3.1.0,<4.0"
pydantic-core = "2.20.1"
psutil = "^5.9.0"
types-psutil = "^7.0.0.20251001"

[tool.poetry.group.dev.dependencies]
mypy = "^1.6.1"
Expand Down
2 changes: 0 additions & 2 deletions src/pwncore/models/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class Container(Model):
problem: fields.ForeignKeyRelation[Problem] = fields.ForeignKeyField(
"models.Problem", on_delete=fields.OnDelete.NO_ACTION
)
problem_id = fields.IntField()
team: fields.ForeignKeyRelation[Team] = fields.ForeignKeyField("models.Team")
team_id = fields.IntField()
flag = fields.TextField()

token = fields.TextField(null=True)
Expand Down
1 change: 0 additions & 1 deletion src/pwncore/models/ctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class BaseProblem(Model):


class Problem(BaseProblem):
id = fields.IntField(pk=True)
image_name = fields.TextField()

# commenting it for now, may be used later
Expand Down
2 changes: 1 addition & 1 deletion src/pwncore/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
router.include_router(ctf.router)
router.include_router(team.router)
router.include_router(leaderboard.router)
router.include_router(admin.router) # Admin routes moved to separate app on port 8081
router.include_router(admin.router)
22 changes: 16 additions & 6 deletions src/pwncore/routes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,15 @@ async def get_resource_usage(response: Response, req: Request):
container_info = {
"container_id": db_container.docker_id[:12],
"team_id": db_container.team_id,
"team_name": (await db_container.team).name,
"team_name": (
(await db_container.team).name if db_container.team else "Unknown"
),
"problem_id": db_container.problem_id,
"problem_name": (await db_container.problem).name,
"problem_name": (
(await db_container.problem).name
if db_container.problem
else "Unknown"
),
"ports": ports,
"cpu_percent": round(cpu_usage, 2),
"memory": {
Expand Down Expand Up @@ -314,10 +320,14 @@ async def get_resource_usage(response: Response, req: Request):
"team_id": db_container.team_id,
"team_name": (
(await db_container.team).name
if db_container.team
else "Unknown"
),
"problem_id": db_container.problem_id,
"problem_name": (
(await db_container.problem).name
if db_container.problem
else "Unknown"
),
"ports": ports,
"status": "error",
Expand Down Expand Up @@ -348,9 +358,9 @@ async def list_docker_containers(response: Response, req: Request):
container_info = {
"docker_id": container.docker_id,
"team_id": container.team_id,
"team_name": container.team.name,
"team_name": container.team.name if container.team else "Unknown",
"problem_id": container.problem_id,
"problem_name": container.problem.name,
"problem_name": container.problem.name if container.problem else "Unknown",
"ports": ports,
}
container_list.append(container_info)
Expand Down Expand Up @@ -434,7 +444,7 @@ async def stop_docker_container(docker_id: str, response: Response, req: Request
try:
await Container.filter(docker_id=docker_id).delete()
ctf = await container.problem
if ctf.static_files:
if ctf and ctf.static_files:
static_path = f"{config.staticfs_data_dir}/{container.team_id}/{docker_id}"
if os.path.exists(static_path):
shutil.rmtree(static_path)
Expand All @@ -453,7 +463,7 @@ async def stop_docker_container(docker_id: str, response: Response, req: Request
@router.get("/ban/list")
async def get_ban_list(request: Request, response: Response) -> JSONResponse:
"""Get banned tags list."""
return JSONResponse({"banned": config.blacklist})
return {"banned": config.blacklist}


@router.post("/ban/{team_id}", status_code=status.HTTP_204_NO_CONTENT)
Expand Down
8 changes: 4 additions & 4 deletions src/pwncore/routes/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ async def get_team_containers(response: Response, jwt: RequireJwt):

result = {}
for container in containers:
if container.problem is not None:
result[container.problem.id] = await container.ports.all().values_list(
"port", flat=True
)
# mypy complains id doesnt exist in Problem
result[container.problem.id] = await container.ports.all().values_list( # type: ignore[attr-defined]
"port", flat=True
)

return result