added password check for DELETE method #7

Merged
dafo5502 merged 2 commits from delete_auth into master 2021-10-28 09:32:24 +02:00
2 changed files with 9 additions and 1 deletions
Showing only changes of commit 120f8cecc3 - Show all commits

View File

@ -53,9 +53,16 @@ def create_app():
@app.route('/presentation/<string:presentation>', methods=['DELETE']) @app.route('/presentation/<string:presentation>', methods=['DELETE'])
def delete_presentation(presentation): def delete_presentation(presentation):
data = request.get_json()
if not data['auth'] or not _valid_credential(data['auth']):
return Response(response="Use correct credentials to access this endpoint", status=401)
shutil.rmtree(os.path.join(storagedir, presentation)) shutil.rmtree(os.path.join(storagedir, presentation))
return Response(response='Deleted {}'.format(presentation)) return Response(response='Deleted {}'.format(presentation))
def _valid_credential(pw):
return config['api']['password'] == pw
@app.route('/presentation/<string:presentation>/<path:path>') @app.route('/presentation/<string:presentation>/<path:path>')
def serve_file(presentation, path): def serve_file(presentation, path):
realpath = safe_join(storagedir, os.path.join(presentation, path)) realpath = safe_join(storagedir, os.path.join(presentation, path))
@ -115,7 +122,7 @@ def create_app():
@app.route('/status/daemon') @app.route('/status/daemon')
def daemon_status(): def daemon_status():
running = False running = False
if daemon_detect.is_running(): if api.daemon_detect.is_running():
running = True running = True
return Response(response=json.dumps({'running': running}), return Response(response=json.dumps({'running': running}),
content_type='application/json') content_type='application/json')

View File

@ -2,6 +2,7 @@
permission_url = https://example.com/perm permission_url = https://example.com/perm
cache_seconds = 30 cache_seconds = 30
log_level = DEBUG log_level = DEBUG
password = dummy
[db] [db]
database = somedatabase database = somedatabase