# CVE-2026-71362 Magento lab — convenience wrapper.
DC := docker compose
TARGET ?= http://127.0.0.1:8080

.PHONY: help up logs wait exploit patch unpatch shell down clean status

help:
	@echo "CVE-2026-71362 — Magento customer-session identity-switch lab"
	@echo ""
	@echo "  make up        Build + start the stack (first boot installs Magento; 15-40 min)"
	@echo "  make wait      Block until the storefront answers HTTP 200"
	@echo "  make logs      Follow the installer / php logs"
	@echo "  make status    Show container status"
	@echo "  make exploit   Run the PoC against \$$TARGET ($(TARGET))"
	@echo "  make patch     Apply Adobe's official APSB26-92 fix (PoC should then FAIL)"
	@echo "  make unpatch   Restore the vulnerable file (PoC should EXPLOIT again)"
	@echo "  make shell     Shell into the php container"
	@echo "  make down      Stop containers"
	@echo "  make clean     Stop + delete volumes (full reset)"

up:
	@test -f .env || cp .env.example .env
	$(DC) up -d --build
	@echo "Stack starting. First boot installs Magento — watch it with:  make logs"
	@echo "Then:  make wait && make exploit"

logs:
	$(DC) logs -f php

status:
	$(DC) ps

wait:
	@echo "Waiting for the storefront at $(TARGET) (install can take 15-40 min on first boot)..."
	@for i in $$(seq 1 240); do \
	  code=$$(curl -s -o /dev/null -w '%{http_code}' $(TARGET)/ || true); \
	  if [ "$$code" = "200" ]; then echo "storefront is up (HTTP 200)"; exit 0; fi; \
	  sleep 15; \
	done; echo "timed out waiting for $(TARGET)"; exit 1

exploit:
	@python3 -c "import requests" 2>/dev/null || pip install -q -r exploit/requirements.txt
	TARGET=$(TARGET) python3 exploit/poc.py

patch:
	bash scripts/patch.sh

unpatch:
	bash scripts/unpatch.sh

shell:
	$(DC) exec php bash

down:
	$(DC) down

clean:
	$(DC) down -v
