Files
CTF/HTB/mentor/app_backkup/app/app/api/admin.py
Simon 82b0759f1e init htb
old htb folders
2023-08-29 21:53:22 +02:00

26 lines
977 B
Python

from fastapi import APIRouter, Depends
from app.api.utils import is_admin, is_logged
from app.api.models import backup
import os
router = APIRouter()
WORK_DIR = os.getenv('WORK_DIR', '/app')
DATABASE_URL = os.getenv('DATABASE_URL', 'postgresql://postgres:postgres@192.168.1.4/hello_fastapi_dev')
@router.get('/', dependencies=[Depends(is_logged), Depends(is_admin)],include_in_schema=False)
async def admin_funcs():
return {"admin_funcs":{"check db connection":"/check","backup the application": "/backup"}}
@router.get('/check',dependencies=[Depends(is_logged), Depends(is_admin)],include_in_schema=False)
async def check_connection():
return {"details": "Not implemented yet!"}
# Take a backup of the application
@router.post("/backup",dependencies=[Depends(is_logged), Depends(is_admin)],include_in_schema=False)
async def backup(payload: backup):
os.system(f'tar -c -f {str(payload.path)}/app_backkup.tar {str(WORK_DIR)} &')
return {"INFO": "Done!"}