#!/bin/sh # RFC 8908 requires application/captive+json and no-cache headers[cite: 2] printf "Content-Type: application/captive+json\r\n"[cite: 2] printf "Cache-Control: private, no-cache, no-store, must-revalidate\r\n\r\n"[cite: 2] CLIENT_IP="$REMOTE_ADDR"[cite: 2] PORTAL_URL="https://portal.example.com:8443/cgi-bin/entry.sh" VENUE_URL="https://example.com"[cite: 2] IS_CAPTIVE="true"[cite: 2] SECONDS_REMAINING=0[cite: 2] if [ -n "$CLIENT_IP" ]; then[cite: 2] CLIENT_DATA=$(ndsctl json "$CLIENT_IP" 2>/dev/null)[cite: 2] # openNDS outputs capitalized "state":"Authenticated" if echo "$CLIENT_DATA" | grep -qi '"state":"authenticated"'; then IS_CAPTIVE="false"[cite: 2] SESSION_END=$(echo "$CLIENT_DATA" | grep -i '"session_end"' | tr -dc '0-9') NOW=$(date +%s)[cite: 2] if [ -n "$SESSION_END" ] && [ "$SESSION_END" -gt "$NOW" ]; then[cite: 2] SECONDS_REMAINING=$((SESSION_END - NOW))[cite: 2] else SECONDS_REMAINING=86400[cite: 2] fi fi fi[cite: 2] cat <