commit 2050078052ff1dd89433c2c8225b0db302e85d5c Author: Tristan Andrus Date: Tue Mar 25 22:38:10 2025 -0600 First commit Signed-off-by: Tristan Andrus diff --git a/basketwatch.py b/basketwatch.py new file mode 100755 index 0000000..8dd4a08 --- /dev/null +++ b/basketwatch.py @@ -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) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7e10602 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +flask