#!/usr/bin/env bash
source "$(dirname "$0")/_lib/common.sh"
require_root
onx_json_input
QPATH="$(onx_json_field quarantine_path '')"
OPATH="$(onx_json_field original_path '')"
[[ -n "$QPATH" ]] || onx_die 1 "quarantine_path required"
# Symlink kaçışını önle: gerçek yolu çöz (yoksa hata), sonra karantina dizini kontrolü RESOLVED yol üzerinde.
QPATH="$(realpath -e "$QPATH" 2>/dev/null)" || onx_die 1 "quarantine file not found"
[[ -n "$OPATH" ]] || onx_die 1 "original_path required"
case "$QPATH" in /var/lib/onoxsoft/quarantine/*) : ;; *) onx_die 1 "not a quarantine path" ;; esac
OPATH="$(realpath -m "$OPATH" 2>/dev/null || printf '%s' "$OPATH")"
case "$OPATH" in /home/*|/var/www/*) : ;; *) onx_die 1 "restore path not allowed" ;; esac
mkdir -p "$(dirname "$OPATH")"
mv -- "$QPATH" "$OPATH" || onx_die 3 "restore failed"
onx_json_out ok true restored_path "$OPATH"
