1010
1111import pwncore .containerASD as containerASD
1212from pwncore .config import config
13- from pwncore .models import Container , Ports , Problem
13+ from pwncore .models import Container , Ports , Problem , SolvedProblem
1414from pwncore .routes .auth import RequireJwt
1515
1616router = APIRouter (tags = ["ctf" ])
@@ -40,6 +40,12 @@ async def start_docker_container(ctf_id: int, response: Response, jwt: RequireJw
4040 response .status_code = 404
4141 return {"msg_code" : config .msg_codes ["ctf_not_found" ]}
4242
43+ team_id = jwt ["team_id" ]
44+ solved = await SolvedProblem .filter (team = team_id , problem = ctf_id ).exists ()
45+ if solved :
46+ response .status_code = 400
47+ return {"msg_code" : config .msg_codes ["ctf_solved" ]}
48+
4349 if ctf .static_flag :
4450 existing_container = await Container .get_or_none (problem = ctf_id )
4551 if existing_container :
@@ -57,7 +63,6 @@ async def start_docker_container(ctf_id: int, response: Response, jwt: RequireJw
5763 "ctf_id" : ctf_id ,
5864 }
5965
60- team_id = jwt ["team_id" ] # From JWT
6166 team_container = await Container .filter (team = team_id , problem = ctf_id )
6267 if team_container :
6368 a , b = team_container [0 ], team_container [1 :]
@@ -242,11 +247,14 @@ async def stopall_docker_container(response: Response, jwt: RequireJwt):
242247 shutil .rmtree (team_path )
243248
244249 for db_container in containers :
245- container = await containerASD .docker_client .containers .get (
246- db_container ["docker_id" ]
247- )
248- await container .kill ()
249- await container .delete ()
250+ try :
251+ container = await containerASD .docker_client .containers .get (
252+ db_container ["docker_id" ]
253+ )
254+ await container .kill ()
255+ await container .delete ()
256+ except Exception :
257+ pass
250258
251259 return {"msg_code" : config .msg_codes ["containers_team_stop" ]}
252260
@@ -274,16 +282,25 @@ async def stop_docker_container(ctf_id: int, response: Response, jwt: RequireJwt
274282 response .status_code = 500
275283 return {"msg_code" : config .msg_codes ["db_error" ]}
276284
277- if ctf .static_files :
278- shutil .rmtree (
279- f"{ config .staticfs_data_dir } /{ team_id } /{ team_container .docker_id } "
280- )
281- return {"msg_code" : config .msg_codes ["container_stop" ]}
285+ try :
286+ if ctf .static_files :
287+ shutil .rmtree (
288+ f"{ config .staticfs_data_dir } /{ team_id } /{ team_container .docker_id } "
289+ )
290+ return {"msg_code" : config .msg_codes ["container_stop" ]}
291+ except :
292+ pass
282293
283294 container = await containerASD .docker_client .containers .get (
284295 team_container .docker_id
285296 )
286- await container .kill ()
287- await container .delete ()
297+ try :
298+ container = await containerASD .docker_client .containers .get (
299+ team_container .docker_id
300+ )
301+ await container .kill ()
302+ await container .delete ()
303+ except Exception :
304+ pass
288305
289306 return {"msg_code" : config .msg_codes ["container_stop" ]}
0 commit comments