From 8bc1ae86e7c0faec5a9781a023a83ab4fdd12cd0 Mon Sep 17 00:00:00 2001 From: Chris Cowan Date: Mon, 20 Oct 2025 15:47:20 -0700 Subject: [PATCH] first commit of bot config --- Dockerfile | 1 - backupbot.env | 23 +++++++++++++++++++++++ docker-compose.yml | 1 - web/backupbot.cgi | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 backupbot.env create mode 100644 web/backupbot.cgi diff --git a/Dockerfile b/Dockerfile index 051862a..c112619 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ -# Use LinuxServer.io Duplicati base FROM linuxserver/duplicati:2.1.0 # Install Docker CLI, bash, python3, btrfs support and all the app directories diff --git a/backupbot.env b/backupbot.env new file mode 100644 index 0000000..d096410 --- /dev/null +++ b/backupbot.env @@ -0,0 +1,23 @@ +# === BackupBot Environment Configuration === +# Used by backup_scheduler.sh and web frontend +# Do not store sensitive credentials in world-readable locations unless necessary + +# Timezone for scheduling backups (affects 3 AM backup) +TZ=America/Los_Angeles + +# Directory to store backup SQL files +BACKUP_DIR=/backups/postgres + +# Log file path +LOG_FILE=/config/log/pgbackup.log + +# Number of retry attempts on failure +MAX_RETRIES=3 + +# Gotify notification configuration (optional) +GOTIFY_URL=http://gotify.example.com +GOTIFY_TOKEN=your_gotify_token_here + +# Backup time (24-hour format) – defaults to 03:00 local time +BACKUP_HOUR=03 +BACKUP_MINUTE=00 diff --git a/docker-compose.yml b/docker-compose.yml index a1cd073..2ff9ff9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,7 +17,6 @@ services: - /srv/backups:/backups:rshared # Docker socket to list containers - /var/run/docker.sock:/var/run/docker.sock:ro - ports: - 8200:8200 - 8201:8080 diff --git a/web/backupbot.cgi b/web/backupbot.cgi new file mode 100644 index 0000000..a7ed333 --- /dev/null +++ b/web/backupbot.cgi @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +import cgi +import cgitb +import os +import json + +cgitb.enable() +print("Content-Type: application/json\n") + +ENV_FILE = "/config/web/backupbot.env" + + +def read_env(): + env = {} + if os.path.exists(ENV_FILE): + with open(ENV_FILE) as f: + for line in f: + line = line.strip() + if line and not line.startswith("#") and "=" in line: + key, val = line.split("=", 1) + env[key.strip()] = val.strip() + return env + + +def write_env(env): + with open(ENV_FILE, "w") as f: + for key, val in env.items(): + f.write(f"{key}={val}\n") + + +form = cgi.FieldStorage() +action = form.getvalue("action") + +if action == "get": + env = read_env() + print(json.dumps(env)) +elif action == "set": + try: + raw = os.environ.get("CONTENT_LENGTH") + length = int(raw) if raw else 0 + data = json.loads(os.read(0, length)) + write_env(data) + print(json.dumps({"status": "ok", "message": "Configuration saved."})) + except Exception as e: + print(json.dumps({"status": "error", "message": str(e)})) +else: + print(json.dumps({"status": "error", "message": "Invalid action"}))