75 lines
2.0 KiB
Bash
75 lines
2.0 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Start a simple Python HTTP server on port 80 for FIPS reachability tests.
|
|
# Run this script on the OTHER qube.
|
|
#
|
|
# Usage:
|
|
# ./start_py_http80.sh [serve_dir]
|
|
#
|
|
# Behavior:
|
|
# - Detects local FIPS IPv6 from fipsctl (if available)
|
|
# - Binds http.server to that FIPS IPv6 address (critical for .fips inbound tests)
|
|
# - Falls back to :: if detection fails
|
|
# - Prints listener info so you can confirm IPv6 bind
|
|
#
|
|
# Cross-reference:
|
|
# - test_qube_pair.sh expects HTTP over .fips on port 80 by default
|
|
# - If server binds only to 0.0.0.0 (IPv4), .fips curl from another qube may fail
|
|
|
|
if ! command -v python3 >/dev/null 2>&1; then
|
|
echo "Error: python3 is required" >&2
|
|
exit 1
|
|
fi
|
|
|
|
SERVE_DIR="${1:-$HOME/fips_http_root}"
|
|
mkdir -p "${SERVE_DIR}"
|
|
|
|
if [[ ! -f "${SERVE_DIR}/index.html" ]]; then
|
|
cat > "${SERVE_DIR}/index.html" <<'HTML'
|
|
<!doctype html>
|
|
<html>
|
|
<head><meta charset="utf-8"><title>FIPS test server</title></head>
|
|
<body>
|
|
<h1>FIPS test server is running on port 80</h1>
|
|
<p>If you can read this over .fips, HTTP over FIPS is working.</p>
|
|
</body>
|
|
</html>
|
|
HTML
|
|
fi
|
|
|
|
BIND_ADDR="::"
|
|
if command -v fipsctl >/dev/null 2>&1; then
|
|
FIPS_IPV6="$(sudo fipsctl show status 2>/dev/null | python3 -c 'import json,sys
|
|
try:
|
|
d=json.loads(sys.stdin.read())
|
|
print(d.get("ipv6_addr") or "")
|
|
except Exception:
|
|
print("")' || true)"
|
|
if [[ -n "${FIPS_IPV6}" ]]; then
|
|
BIND_ADDR="${FIPS_IPV6}"
|
|
fi
|
|
fi
|
|
|
|
echo "Serving directory: ${SERVE_DIR}"
|
|
echo "Binding python HTTP server to [${BIND_ADDR}]:80 (sudo required)"
|
|
|
|
echo "Stopping any existing python http.server processes..."
|
|
sudo pkill -f "python3 -m http.server" >/dev/null 2>&1 || true
|
|
|
|
cd "${SERVE_DIR}"
|
|
|
|
echo "Starting server..."
|
|
# Start in background briefly so we can validate listener, then wait on it.
|
|
sudo python3 -m http.server 80 --bind "${BIND_ADDR}" &
|
|
SERVER_PID=$!
|
|
sleep 1
|
|
|
|
echo "Listener check:"
|
|
sudo ss -lntp | grep ':80 ' || true
|
|
|
|
echo "Server PID: ${SERVER_PID}"
|
|
echo "Press Ctrl+C to stop."
|
|
wait "${SERVER_PID}"
|
|
|