Quote from: Jingles on May 23, 2026, 05:05:53 PMHow do I access the console if I can't SSH into it?He means locally, hook up a monitor and keyboard to the machine.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts MenuQuote from: Jingles on May 23, 2026, 05:05:53 PMHow do I access the console if I can't SSH into it?He means locally, hook up a monitor and keyboard to the machine.
#!/usr/bin/env bash
set -Eeuo pipefail
OPNSENSE_HOSTS=("https://opnsense.example.com") # add more for HA
API_KEY="<API KEY HERE>"
API_SECRET="<API SECRET HERE>"
ENDPOINT="/api/core/firmware/poweroff"
CONNECT_TIMEOUT=3
MAX_TIME=10
RETRIES=3
RETRY_DELAY=2
log(){ logger -t ppb-opnsense -- "$*"; echo "[$(date -Is)] $*"; }
call_shutdown() {
local url="${1%/}${ENDPOINT}"
local args=(
--silent --show-error
--header "Content-Type: application/json"
--user "${API_KEY}:${API_SECRET}"
--data '{}'
--connect-timeout "$CONNECT_TIMEOUT"
--max-time "$MAX_TIME"
--write-out "HTTP_CODE=%{http_code}\n"
--output /dev/null
)
# With LE, system trust store is fine; no -k used.
local out rc code
for ((i=1;i<=RETRIES;i++)); do
set +e
out=$(curl -X POST "${args[@]}" "$url" 2>&1); rc=$?
set -e
code=""; [[ "$out" =~ HTTP_CODE=([0-9]{3}) ]] && code="${BASH_REMATCH[1]}"
if [[ "$code" =~ ^2..$ || "$code" == "000" ]]; then
log "Accepted by $url (HTTP:${code:-none})."
return 0
fi
log "Attempt $i failed (rc:$rc HTTP:${code:-none}). Out: $out"
(( i < RETRIES )) && sleep "$RETRY_DELAY"
done
return 1
}
main(){
command -v curl >/dev/null || { log "ERROR: curl not found"; exit 2; }
local fail=0
for h in "${OPNSENSE_HOSTS[@]}"; do
log "Requesting shutdown: $h"
call_shutdown "$h" || { log "ERROR: $h did not acknowledge"; ((fail++)); }
done
(( fail==0 )) && { log "All shutdown calls issued."; exit 0; } || exit 1
}
main "$@"