#!/usr/bin/env bash
# onx-terminal-secret — terminal.secret'i oku, ttyd WS auth_token üret → JSON.
# Sadece panel (root sysapi) çağırır; panel da yalnız admin+IP'li connect'te döner.
set -uo pipefail
cat >/dev/null 2>&1 || true
command -v jq >/dev/null 2>&1 || { printf '{"ok":false,"error":"jq yok"}\n'; exit 2; }
F=/etc/onoxsoft/terminal.secret
[[ -s "$F" ]] || { echo '{"ok":false,"error":"secret yok (once onx-terminal-install calistir)"}'; exit 3; }
SECRET="$(cat "$F")"
# ttyd -c auth: istemci ilk WS mesajı {"AuthToken": base64("onox:<secret>")}
TOKEN="$(printf 'onox:%s' "$SECRET" | base64 -w0)"
jq -nc --arg t "$TOKEN" '{ok:true,auth_token:$t}'
exit 0
