diff --git a/app/sbin/ODOO_19/import b/app/sbin/ODOO_19/import index 27b9d3a..8b5d6af 100644 --- a/app/sbin/ODOO_19/import +++ b/app/sbin/ODOO_19/import @@ -11,7 +11,7 @@ exec > /4server/data/log/importDb.log 2>&1 echo "$(date '+%Y-%m-%d %H:%M') Import file $1" # Generate random 8-digit filename -RANDOM_FILE="/4server/tmp/$(printf "%08d" $((RANDOM % 100000000))).zip" +RANDOM_FILE="/4server/tmp/import_$(date '+%Y%m%d_%H%M').zip" # Download file from Google Drive using gdown gdown "$1" -O "$RANDOM_FILE" diff --git a/app/sbin/ODOO_19/listModules b/app/sbin/ODOO_19/listModules new file mode 100755 index 0000000..aa4f0e7 --- /dev/null +++ b/app/sbin/ODOO_19/listModules @@ -0,0 +1,30 @@ +#!/bin/bash +export PATH=/4PROJECTS/bin:$PATH +if [ ! -n "$1" ]; then + echo "Missing Parameters " + exit 0 +fi + +UUID=$1 + +source /4server/sbin/helpers + +get_contract_info + +# Query installed Odoo modules and output as CSV (disable pager for non-interactive use) +PGPASSWORD="$POSTGRES_ADMIN_PASSWORD" PAGER= psql \ + -h "$POSTGRES_HOST" \ + -U "$POSTGRES_ADMIN_USER" \ + -p "$POSTGRES_PORT" \ + -d "$UUID" \ + --csv \ + -c " +SELECT + name, + latest_version, + author, + summary +FROM ir_module_module +WHERE state = 'installed' +ORDER BY name; +" diff --git a/app/sbin/api b/app/sbin/api index 8819f1b..d7ac081 100755 --- a/app/sbin/api +++ b/app/sbin/api @@ -131,6 +131,10 @@ class MoveRequest(BaseModel): source: str destination: str +class AddKeyRequest(BaseModel): + key: str + uuid: str + # ---------------------- Routes ---------------------- @app.get("/", include_in_schema=False) @@ -209,7 +213,11 @@ def start_container(request: UUIDRequest): @app.post("/container/stop", dependencies=[Depends(verify_api_key)]) def stop_container(request: UUIDRequest): - return {"message": run_command([f"{BIN_PATH}/stopContainer", request.UUID])} + try: + return {"message": run_command([f"{BIN_PATH}/stopContainer", request.UUID])} + except HTTPException: + # Command failed, but continue without error to the API + return {"message": "Container stop command executed (may have failed)"} @app.post("/container/nuke", dependencies=[Depends(verify_api_key)]) @@ -346,6 +354,25 @@ def git_tool(request: CommandRequest): output = run_command(command) return {"message": output} + +@app.post("/client/addGitKey", dependencies=[Depends(verify_api_key)]) +def add_git_key(request: AddKeyRequest): + if not request.key or not request.uuid: + raise HTTPException(status_code=400, detail="Key and uuid are required") + + file_path = f"/4server/data/{request.uuid}/git-server/keys/id_rsa.pub" + + try: + # Ensure the directory exists + os.makedirs(os.path.dirname(file_path), exist_ok=True) + # Write the key to the file + with open(file_path, "w", encoding="utf-8") as f: + f.write(request.key) + except Exception as e: + raise HTTPException(status_code=500, detail=f"Failed to save key: {str(e)}") + + return {"message": f"Key saved for container {request.uuid}", "file": file_path} + @app.get("/client/logs/{uuid}", dependencies=[Depends(verify_api_key)]) async def get_odoo_log_summary(uuid: str): if not re.fullmatch(r"[0-9a-fA-F\-]+", uuid): diff --git a/app/sbin/backup/N8N b/app/sbin/backup/N8N new file mode 100755 index 0000000..ce203b4 --- /dev/null +++ b/app/sbin/backup/N8N @@ -0,0 +1,18 @@ +#!/bin/bash + +set -euo pipefail # Fail on error, undefined variables, and pipe errors + +# Create backup filename +FILENAME="$(date +"%Y%m%d_%H%M").zip" +BACKUP_DIR="/BACKUP/$UUID" +mkdir -p "$BACKUP_DIR" + +tar -czvf "$BACKUP_DIR/$FILENAME" -C "/4server/data" "$UUID" + +# Remove old backups beyond the configured slots +ls -t "$BACKUP_DIR"/[0-9]*.zip 2>/dev/null | tail -n +$((BACKUP_SLOTS + 1)) | while read -r file; do + echo "Deleting old backup: $file" + doas rm -f "$file" +done + + diff --git a/app/sbin/backup/ODOO_17 b/app/sbin/backup/ODOO_17 new file mode 100755 index 0000000..3745d3c --- /dev/null +++ b/app/sbin/backup/ODOO_17 @@ -0,0 +1,48 @@ +#!/bin/bash +# Backup Odoo database script +# Author: Your Name +# Description: Dumps Odoo DB, manages backups, and sets permissions + +set -euo pipefail # Fail on error, undefined variables, and pipe errors + +# Load helper functions +source /4server/sbin/helpers + +# Get contract info +get_contract_info + +# Export Odoo database password +export ODOO_DB_PASSWORD +ODOO_DB_PASSWORD=$(echo "$SECRET" | jq -r '.psql') + +# Display basic info +echo "UUID: $UUID" +echo "Backup slots: $BACKUP_SLOTS" + +# Create backup filename +FILENAME="$(date +"%Y%m%d_%H%M").zip" +BACKUP_DIR="/BACKUP/$UUID" + +# Ensure backup directory exists +mkdir -p "$BACKUP_DIR" + +# Perform database dump using docker +doas docker exec "$UUID" odoo db \ + --db_host beedb \ + -r "$UUID" \ + -w "$ODOO_DB_PASSWORD" \ + --data-dir /home/odoo/.local/share/Odoo/ \ + dump "$UUID" "/mnt/backup/$FILENAME" + +# Set permissions for backup files +doas chmod 600 "$BACKUP_DIR"/* +doas docker exec "$UUID" chown odoo:odoo -R /mnt/backup + + +# Remove old backups beyond the configured slots +ls -t "$BACKUP_DIR"/[0-9]*.zip 2>/dev/null | tail -n +$((BACKUP_SLOTS + 1)) | while read -r file; do + echo "Deleting old backup: $file" + doas rm -f "$file" +done + + diff --git a/app/sbin/backup/ODOO_18 b/app/sbin/backup/ODOO_18 new file mode 100755 index 0000000..3745d3c --- /dev/null +++ b/app/sbin/backup/ODOO_18 @@ -0,0 +1,48 @@ +#!/bin/bash +# Backup Odoo database script +# Author: Your Name +# Description: Dumps Odoo DB, manages backups, and sets permissions + +set -euo pipefail # Fail on error, undefined variables, and pipe errors + +# Load helper functions +source /4server/sbin/helpers + +# Get contract info +get_contract_info + +# Export Odoo database password +export ODOO_DB_PASSWORD +ODOO_DB_PASSWORD=$(echo "$SECRET" | jq -r '.psql') + +# Display basic info +echo "UUID: $UUID" +echo "Backup slots: $BACKUP_SLOTS" + +# Create backup filename +FILENAME="$(date +"%Y%m%d_%H%M").zip" +BACKUP_DIR="/BACKUP/$UUID" + +# Ensure backup directory exists +mkdir -p "$BACKUP_DIR" + +# Perform database dump using docker +doas docker exec "$UUID" odoo db \ + --db_host beedb \ + -r "$UUID" \ + -w "$ODOO_DB_PASSWORD" \ + --data-dir /home/odoo/.local/share/Odoo/ \ + dump "$UUID" "/mnt/backup/$FILENAME" + +# Set permissions for backup files +doas chmod 600 "$BACKUP_DIR"/* +doas docker exec "$UUID" chown odoo:odoo -R /mnt/backup + + +# Remove old backups beyond the configured slots +ls -t "$BACKUP_DIR"/[0-9]*.zip 2>/dev/null | tail -n +$((BACKUP_SLOTS + 1)) | while read -r file; do + echo "Deleting old backup: $file" + doas rm -f "$file" +done + + diff --git a/app/sbin/backupContainer b/app/sbin/backupContainer index 589b5bd..fdfe1b1 100755 --- a/app/sbin/backupContainer +++ b/app/sbin/backupContainer @@ -22,13 +22,20 @@ SECOND_PART=$(echo "$UUID" | cut -d'-' -f2) # Decide which script to run case "$SECOND_PART" in - 001) - "$BIN_PATH/backup/n8n" + 001) + "$BIN_PATH/backup/N8N" ;; - 003) + 002) + "$BIN_PATH/backup/ODOO_18" + ;; + 003) "$BIN_PATH/backup/ODOO_19" ;; - *) + 004) + "$BIN_PATH/backup/ODOO_17" + ;; + + *) echo "Unknown UUID type: $SECOND_PART" exit 2 ;; diff --git a/app/sbin/start/n8n b/app/sbin/start/n8n index 0141719..acec4b1 100755 --- a/app/sbin/start/n8n +++ b/app/sbin/start/n8n @@ -28,15 +28,27 @@ docker run -d \ --cap-add=SYS_ADMIN \ --security-opt seccomp=unconfined \ --restart=always \ + -e N8N_EMAIL_MODE=smtp \ + -e N8N_SMTP_HOST="smtp.strato.de" \ + -e N8N_SMTP_PORT=587 \ + -e N8N_SMTP_USER="n8n@odoo4projects.com" \ + -e N8N_SMTP_PASS="Airbus12N@N" \ + -e N8N_SMTP_SENDER="n8n " \ + -e N8N_SMTP_SSL=false \ -e N8N_HOST="${UUID}.odoo4projects.com" \ -e N8N_PORT=5678 \ -e N8N_PROTOCOL=https \ + -e N8N_FORMDATA_FILE_SIZE_MAX=3000 \ + -e N8N_TRUST_PROXY=true \ -e NODE_ENV=production \ + -e EXECUTIONS_PRUNE=true \ + -e EXECUTIONS_PRUNE_MAX_AGE=48 \ -e WEBHOOK_URL="https://${UUID}.odoo4projects.com/" \ -e GENERIC_TIMEZONE="UTC-3" \ + -e N8N_BLOCK_ENV_ACCESS_AND_PROCESS_INFORMATION=true \ -e N8N_CUSTOM_EXTENSIONS="/usr/local/share/n8n/custom" \ -v "/4server/data/${UUID}/n8n:/home/node/.n8n" \ - -v "/4server/data/${UUID}/backup:/data" \ + -v "/4server/data/${UUID}/data:/data" \ -v "/4server/data/${UUID}/backup:/backup" \ --label "traefik.enable=true" \ --label "traefik.http.routers.${UUID}.rule=Host(\`${UUID}.odoo4projects.com\`)" \ diff --git a/app/vault/host_vars.img b/app/vault/host_vars.img index e9b9937..34b9ce7 100644 Binary files a/app/vault/host_vars.img and b/app/vault/host_vars.img differ