From 9b2c79b039fa6c860f4db13c62a68391fbed62da Mon Sep 17 00:00:00 2001 From: lelo Date: Sat, 5 Apr 2025 16:15:37 +0000 Subject: [PATCH] config into config files --- .gitignore | 3 +- auth.py | 2 +- folder_config.json.example.json | 13 ------ check_ssh_tunnel.sh => mount_folder.sh | 64 ++++++++++---------------- 4 files changed, 28 insertions(+), 54 deletions(-) delete mode 100644 folder_config.json.example.json rename check_ssh_tunnel.sh => mount_folder.sh (72%) diff --git a/.gitignore b/.gitignore index 5ecf119..d125949 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,6 @@ /search.db /access_log.db /access_log.db.bak -/folder_config.json +/folder_permission_config.json +/folder_mount_config.json /.env \ No newline at end of file diff --git a/auth.py b/auth.py index 182746c..3fa9ee6 100644 --- a/auth.py +++ b/auth.py @@ -14,7 +14,7 @@ def require_secret(f): def decorated_function(*args, **kwargs): global folder_config if not folder_config: - with open('folder_config.json') as file: + with open('folder_permission_config.json') as file: folder_config = json.load(file) def is_valid(config_item, provided_secret): diff --git a/folder_config.json.example.json b/folder_config.json.example.json deleted file mode 100644 index 39256f1..0000000 --- a/folder_config.json.example.json +++ /dev/null @@ -1,13 +0,0 @@ -[ - { - "secret" : "dev_key_f83745ft0g5rg3", - "validity" : "31.12.2030", - "folders": [ - { - "foldername": "My Folder", - "folderpath": "\\\\path\\if\\using\\windows" - } - ] - - } -] \ No newline at end of file diff --git a/check_ssh_tunnel.sh b/mount_folder.sh similarity index 72% rename from check_ssh_tunnel.sh rename to mount_folder.sh index e0f1c0f..763d2b9 100755 --- a/check_ssh_tunnel.sh +++ b/mount_folder.sh @@ -1,50 +1,36 @@ #!/bin/bash ############################################################################### -# Configuration Section +# Configuration Section (Loaded from config.json) ############################################################################### -# Server 1 Configuration -SERVER1_SSH_USER="root" -SERVER1_SSH_SERVER="bethaus-speyer.de" -SERVER1_SSH_SERVER_PORT=1122 # Remote SSH server port for Server 1 -SERVER1_REMOTE_NFS_PORT=2049 # Remote NFS server port (usually 2049) -SERVER1_LOCAL_PORT_BASE=2022 # Base local port for SSH tunnel (will add index offset) -# Define multiple mount configurations for Server 1 -# Each index corresponds to a mount point and NFS share. -SERVER1_MOUNT_POINTS=( - "/mnt/Gottesdienste Speyer" - "/mnt/Besondere Gottesdienste" - "/mnt/Liedersammlung" - "/mnt/Hochzeiten Speyer" - "/mnt/app_share" -) -SERVER1_NFS_SHARES=( - "/volume1/Aufnahme-stereo/010 Gottesdienste ARCHIV" - "/volume1/Aufnahme-stereo/013 Besondere Gottesdienste" - "/volume1/Aufnahme-stereo/014 Liedersammlung" - "/volume1/Aufnahme-stereo/021 Hochzeiten in Speyer" - "/volume1/app_share" -) +CONFIG_FILE="folder_mount_config.json" -# Server 2 Configuration -SERVER2_SSH_USER="root" -SERVER2_SSH_SERVER="bethaus-schwegenheim.de" -SERVER2_SSH_SERVER_PORT=1122 # Remote SSH server port for Server 2 -SERVER2_REMOTE_NFS_PORT=2049 # Remote NFS server port -SERVER2_LOCAL_PORT_BASE=3022 # Base local port for SSH tunnel (will add index offset) +# Ensure jq is installed before proceeding. +if ! command -v jq >/dev/null 2>&1; then + echo "[ERROR] 'jq' is not installed. Please install jq and try again." + exit 1 +fi -# Define multiple mount configurations for Server 2 -SERVER2_MOUNT_POINTS=( - "/mnt/Gottesdienste Schwegenheim" - "/mnt/Hochzeiten Schwegenheim" -) -SERVER2_NFS_SHARES=( - "/volume1/Aufnahme-stereo/010 Gottesdienste ARCHIV" - "/volume1/Aufnahme-stereo/020 Hochzeiten" -) +# Load Server 1 configuration +SERVER1_SSH_USER=$(jq -r '.SERVER1.SSH_USER' "$CONFIG_FILE") +SERVER1_SSH_SERVER=$(jq -r '.SERVER1.SSH_SERVER' "$CONFIG_FILE") +SERVER1_SSH_SERVER_PORT=$(jq -r '.SERVER1.SSH_SERVER_PORT' "$CONFIG_FILE") +SERVER1_REMOTE_NFS_PORT=$(jq -r '.SERVER1.REMOTE_NFS_PORT' "$CONFIG_FILE") +SERVER1_LOCAL_PORT_BASE=$(jq -r '.SERVER1.LOCAL_PORT_BASE' "$CONFIG_FILE") +readarray -t SERVER1_MOUNT_POINTS < <(jq -r '.SERVER1.MOUNT_POINTS[]' "$CONFIG_FILE") +readarray -t SERVER1_NFS_SHARES < <(jq -r '.SERVER1.NFS_SHARES[]' "$CONFIG_FILE") -# List of server identifiers (must match the prefix of configuration variables) +# Load Server 2 configuration +SERVER2_SSH_USER=$(jq -r '.SERVER2.SSH_USER' "$CONFIG_FILE") +SERVER2_SSH_SERVER=$(jq -r '.SERVER2.SSH_SERVER' "$CONFIG_FILE") +SERVER2_SSH_SERVER_PORT=$(jq -r '.SERVER2.SSH_SERVER_PORT' "$CONFIG_FILE") +SERVER2_REMOTE_NFS_PORT=$(jq -r '.SERVER2.REMOTE_NFS_PORT' "$CONFIG_FILE") +SERVER2_LOCAL_PORT_BASE=$(jq -r '.SERVER2.LOCAL_PORT_BASE' "$CONFIG_FILE") +readarray -t SERVER2_MOUNT_POINTS < <(jq -r '.SERVER2.MOUNT_POINTS[]' "$CONFIG_FILE") +readarray -t SERVER2_NFS_SHARES < <(jq -r '.SERVER2.NFS_SHARES[]' "$CONFIG_FILE") + +# Define list of server identifiers (must match JSON keys) SERVERS=("SERVER1" "SERVER2") ###############################################################################