Skip to content

Commit 715e9c4

Browse files
authored
Revert "feat: admin dashboard and static ctfs"
1 parent b73aea9 commit 715e9c4

File tree

16 files changed

+63
-437
lines changed

16 files changed

+63
-437
lines changed

.github/workflows/tox.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
python-version: [
16+
"3.11",
1617
"3.12"
1718
]
1819

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ __pycache__/
55

66
# C extensions
77
*.so
8-
data/
8+
99
# Distribution / packaging
1010
.Python
1111
build/

Dockerfile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
FROM python:3.12-slim
22

3-
RUN apt-get update && apt-get install -y --no-install-recommends build-essential gcc python3-dev
43
WORKDIR /app
54

65
RUN pip install poetry
@@ -16,9 +15,7 @@ RUN poetry install
1615

1716
WORKDIR /app/src
1817

19-
WORKDIR /app/src
20-
2118
EXPOSE 8000
22-
EXPOSE 8081
23-
# Run both main app and admin app
24-
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"]
19+
20+
# Run FastAPI with Gunicorn
21+
CMD ["gunicorn", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", "pwncore:app", "--bind", "0.0.0.0:8000", "--log-level", "debug"]

docker-compose.yaml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ services:
55
dockerfile: Dockerfile
66
ports:
77
- ${PORT}:8000
8-
- ${PORT_ADMIN}:8081
98
environment:
109
- DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
1110
- WORKERS=${WORKERS}
1211
volumes:
1312
- /var/run/docker.sock:/var/run/docker.sock
1413
- ${CONFIG_FILE}:/app/src/pwncore/config.py
15-
# - ./src:/app/src
1614
depends_on:
1715
- db
1816

@@ -34,10 +32,16 @@ services:
3432
ports:
3533
- 5432:5432
3634

35+
# admin_db:
36+
# image: nocodb/nocodb:latest
37+
# environment:
38+
# NC_DB: pg://db:5432?u=${POSTGRES_USER}&p=${POSTGRES_PASSWORD}&d=${POSTGRES_DB}
39+
# volumes:
40+
# - nc_data:/usr/app/data
41+
# ports:
42+
# - ${PORT_ADMIN}:8080
43+
# depends_on:
44+
# - db
3745

38-
# admin_db:
39-
# image: nocodb/nocodb:latest
40-
# volumes:
41-
# - ./data:/usr/app/data
42-
# ports:
43-
# - 8001:8080
46+
# volumes:
47+
# nc_data: {}

poetry.lock

Lines changed: 1 addition & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ multidict = "^6.0.5"
2828
gunicorn = "^23.0.0"
2929
bcrypt = ">3.1.0,<4.0"
3030
pydantic-core = "2.20.1"
31-
psutil = "^5.9.0"
32-
types-psutil = "^7.0.0.20251001"
3331

3432
[tool.poetry.group.dev.dependencies]
3533
mypy = "^1.6.1"

src/pwncore/__init__.py

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import shutil
21
from contextlib import asynccontextmanager
3-
from logging import getLogger
42

3+
import shutil
54
import aiodocker
6-
import jwt
7-
from fastapi import FastAPI, Request, Response, status
5+
from logging import getLogger
6+
from fastapi import FastAPI
87
from fastapi.middleware.cors import CORSMiddleware
98
from tortoise import Tortoise
109

@@ -13,11 +12,9 @@
1312
import pwncore.routes as routes
1413
from pwncore.config import config
1514
from pwncore.models import Container
16-
from pwncore.routes.auth import JwtInfo
1715

1816
logger = getLogger(__name__)
1917

20-
2118
@asynccontextmanager
2219
async def app_lifespan(app: FastAPI):
2320
# Startup
@@ -75,25 +72,3 @@ async def app_lifespan(app: FastAPI):
7572
allow_methods=["*"],
7673
allow_headers=["*"],
7774
)
78-
79-
80-
@app.middleware("http")
81-
async def check_blacklist(
82-
request: Request,
83-
call_next, # noqa: ANN001
84-
):
85-
"""Middleware to handle bans."""
86-
try:
87-
token = request.headers["authorization"].split(" ")[1] # Remove Bearer
88-
89-
decoded_token: JwtInfo = jwt.decode(
90-
token,
91-
config.jwt_secret,
92-
algorithms=["HS256"],
93-
)
94-
team_id = decoded_token["team_id"]
95-
if team_id in config.blacklist:
96-
return Response(status_code=status.HTTP_403_FORBIDDEN)
97-
except KeyError:
98-
pass
99-
return await call_next(request)

src/pwncore/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
def run_dev():
5-
65
uvicorn.run("pwncore:app", host="127.0.0.1", port=8080, reload=True)
76

87

src/pwncore/config.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
2-
import warnings
2+
import bcrypt
33
from dataclasses import dataclass
4-
4+
import warnings
55
from passlib.hash import bcrypt_sha256
66

77
"""
@@ -65,7 +65,6 @@ class Config:
6565
staticfs_data_dir: str
6666
staticfs_jwt_secret: str
6767
admin_hash: str
68-
blacklist: list[int]
6968

7069

7170
config = Config(
@@ -74,7 +73,7 @@ class Config:
7473
db_url=os.environ.get("DATABASE_URL", "sqlite://:memory:"),
7574
# docker_url=None, # None for default system docker
7675
# Or set it to an arbitrary URL for testing without Docker
77-
docker_url=None,
76+
docker_url="http://google.com",
7877
flag="C0D",
7978
max_containers_per_team=3,
8079
jwt_secret="mysecret",
@@ -86,13 +85,9 @@ class Config:
8685
staticfs_data_dir=os.environ.get("STATIC_DATA_DIR", "/data"),
8786
staticfs_jwt_secret="PyMioVKFXHymQd+n7q5geOsT6fSYh3gDVw3GqilW+5U=",
8887
admin_hash=admin_hash_value,
89-
blacklist=[],
9088
)
9189

9290
# Warn in production if env not loaded
9391
if not config.development and using_default_admin:
94-
warnings.warn(
95-
"Default admin hash being used in production!",
96-
RuntimeWarning,
97-
stacklevel=2,
98-
)
92+
warnings.warn("Default admin hash being used in production!", RuntimeWarning)
93+

src/pwncore/models/container.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ class Container(Model):
1818
problem: fields.ForeignKeyRelation[Problem] = fields.ForeignKeyField(
1919
"models.Problem", on_delete=fields.OnDelete.NO_ACTION
2020
)
21-
problem_id = fields.IntField()
2221
team: fields.ForeignKeyRelation[Team] = fields.ForeignKeyField("models.Team")
23-
team_id = fields.IntField()
2422
flag = fields.TextField()
25-
26-
token = fields.TextField(null=True)
23+
24+
token = fields.TextField()
2725
ports: fields.ReverseRelation[Ports]
2826

2927

0 commit comments

Comments
 (0)