From 1663d2d2121d6e9ed472198bae904a64248cb960 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Fri, 9 Oct 2026 12:56:34 +0200 Subject: [PATCH] o: fix approve/deny to handle array of pending requests --- data/scripts/o | 70 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/data/scripts/o b/data/scripts/o index 2b7fe5e..c2623af 100755 --- a/data/scripts/o +++ b/data/scripts/o @@ -316,24 +316,37 @@ cmd_approve() { local bypass_path="session/$CTX_SESSION/bypass" local pending pending=$(ollie-9p read "$bypass_path" 2>/dev/null || true) - if [[ -z "$pending" ]]; then + if [[ -z "$pending" || "$pending" == "[]" || "$pending" == "null" ]]; then echo "no pending bypass request" return 0 fi - local id - id=$(echo "$pending" | jq -r '.id' 2>/dev/null) + + # Normalize to array + local arr + arr=$(echo "$pending" | jq 'if type == "array" then . else [.] end' 2>/dev/null) + + # Find the request to approve + local req + if [[ -n "$req_id" ]]; then + req=$(echo "$arr" | jq -r --arg id "$req_id" '.[] | select(.id == $id)' 2>/dev/null) + if [[ -z "$req" ]]; then + echo "error: no pending request with id $req_id" >&2 + exit 1 + fi + else + req=$(echo "$arr" | jq -r '.[0]' 2>/dev/null) + fi + + local id cmd cwd + id=$(echo "$req" | jq -r '.id' 2>/dev/null) + cmd=$(echo "$req" | jq -r '.cmd | split("\n")[0]' 2>/dev/null) + cwd=$(echo "$req" | jq -r '.cwd' 2>/dev/null) + if [[ -z "$id" || "$id" == "null" ]]; then echo "error: could not parse bypass request" >&2 exit 1 fi - # If request ID specified, verify it matches - if [[ -n "$req_id" && "$req_id" != "$id" ]]; then - echo "error: request id mismatch (pending: $id, requested: $req_id)" >&2 - exit 1 - fi - local cmd cwd - cmd=$(echo "$pending" | jq -r '.cmd' 2>/dev/null) - cwd=$(echo "$pending" | jq -r '.cwd' 2>/dev/null) + echo "[$id] approving: $cmd" echo " cwd: $cwd" printf '%s approve' "$id" | ollie-9p write "$bypass_path" @@ -350,24 +363,37 @@ cmd_deny() { local bypass_path="session/$CTX_SESSION/bypass" local pending pending=$(ollie-9p read "$bypass_path" 2>/dev/null || true) - if [[ -z "$pending" ]]; then + if [[ -z "$pending" || "$pending" == "[]" || "$pending" == "null" ]]; then echo "no pending bypass request" return 0 fi - local id - id=$(echo "$pending" | jq -r '.id' 2>/dev/null) + + # Normalize to array + local arr + arr=$(echo "$pending" | jq 'if type == "array" then . else [.] end' 2>/dev/null) + + # Find the request to deny + local req + if [[ -n "$req_id" ]]; then + req=$(echo "$arr" | jq -r --arg id "$req_id" '.[] | select(.id == $id)' 2>/dev/null) + if [[ -z "$req" ]]; then + echo "error: no pending request with id $req_id" >&2 + exit 1 + fi + else + req=$(echo "$arr" | jq -r '.[0]' 2>/dev/null) + fi + + local id cmd cwd + id=$(echo "$req" | jq -r '.id' 2>/dev/null) + cmd=$(echo "$req" | jq -r '.cmd | split("\n")[0]' 2>/dev/null) + cwd=$(echo "$req" | jq -r '.cwd' 2>/dev/null) + if [[ -z "$id" || "$id" == "null" ]]; then echo "error: could not parse bypass request" >&2 exit 1 fi - # If request ID specified, verify it matches - if [[ -n "$req_id" && "$req_id" != "$id" ]]; then - echo "error: request id mismatch (pending: $id, requested: $req_id)" >&2 - exit 1 - fi - local cmd cwd - cmd=$(echo "$pending" | jq -r '.cmd' 2>/dev/null) - cwd=$(echo "$pending" | jq -r '.cwd' 2>/dev/null) + echo "[$id] denying: $cmd" echo " cwd: $cwd" printf '%s deny' "$id" | ollie-9p write "$bypass_path"