First commit
Signed-off-by: Tristan Andrus <tristan@tristanandrus.com>
This commit is contained in:
commit
2050078052
|
|
@ -0,0 +1,34 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from flask import Flask, request, jsonify
|
||||||
|
import subprocess
|
||||||
|
import base64
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
UNENCODED_AUTH_TOKEN='PitD5xB+Wq6uH7W7UfPtoJo4F6UfWZ9yLrSKZ0bKg9EGoUrK2W77TEI5Y5x1j4uzluqleOo8TGZq2w=='
|
||||||
|
AUTH_TOKEN=base64.b64encode(f"me:{UNENCODED_AUTH_TOKEN}".encode('utf-8')).decode('utf-8')
|
||||||
|
|
||||||
|
REMOTE_DIRECTORY="cymodoce:./basket/*"
|
||||||
|
LOCAL_DEST="/serve/data/basket"
|
||||||
|
PORT=35350
|
||||||
|
|
||||||
|
@app.route('/requestsync', methods=['POST'])
|
||||||
|
def requestsync():
|
||||||
|
# Check for auth token
|
||||||
|
auth_header = request.headers.get('Authorization')
|
||||||
|
if auth_header != f"Basic {AUTH_TOKEN}":
|
||||||
|
print(f"Wrong auth token. Was expecting: {AUTH_TOKEN}\nGot: {auth_header}")
|
||||||
|
return jsonify({"error": "Unauthorized"}), 403
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Run rsync
|
||||||
|
print("Sync requested... running now.")
|
||||||
|
#subprocess.run(['rsync', '-ravzL', REMOTE_DIRECTORY, LOCAL_DEST], check=True)
|
||||||
|
return jsonify({'status': 'OK'})
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
return jsonify({"error": 'rsync failed', 'details': str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(host='0.0.0.0', port=PORT)
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
flask
|
||||||
Loading…
Reference in New Issue