Browse Source

* Added configuration dump capabilities which address #21

* Removed unused code.
pull/29/head
Per-Arne Andersen 5 years ago
parent
commit
b56a9db335
  1. 6
      wg_dashboard_backend/routers/v1/user.py
  2. 29
      wg_dashboard_backend/routers/v1/wg.py

6
wg_dashboard_backend/routers/v1/user.py

@ -78,9 +78,3 @@ def create_user(
)):
raise HTTPException(status_code=400, detail="Could not create user")
return login_for_access_token(OAuth2PasswordRequestForm(
username=form_data.username,
password=form_data.password,
scope=""
), sess)

29
wg_dashboard_backend/routers/v1/wg.py

@ -1,8 +1,14 @@
from fastapi import APIRouter
from datetime import datetime
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from zipfile import ZipFile
from io import BytesIO
import middleware
from starlette.responses import StreamingResponse
import schemas
import script.wireguard
import db.wireguard
router = APIRouter()
@ -23,3 +29,24 @@ def generate_key_pair():
private_key=private_key,
public_key=public_key
)
@router.get("/dump")
def dump_database(
sess: Session = Depends(middleware.get_db)
):
in_memory = BytesIO()
zf = ZipFile(in_memory, mode="w")
for server in db.wireguard.server_get_all(sess):
zf.writestr(f"{server.interface}/{server.interface}.conf", server.configuration)
for peer in server.peers:
zf.writestr(f"{server.interface}/peers/{peer.name}_{peer.address.replace('.','-')}.conf", server.configuration)
zf.close()
in_memory.seek(0)
now = datetime.now().strftime("%m-%d-%Y-%H:%M:%S")
return StreamingResponse(in_memory, media_type="application/zip", headers={
"Content-Disposition": f'attachment; filename="wg-manager-dump-{now}.zip"'
})

Loading…
Cancel
Save