secubox-openwrt/package/secubox/secubox-master-link/files/www/api/master-link/approve
CyberMind-FR c4c829a593 fix(master-link): Suppress p2p-mesh.sh stdout noise from sourced libraries
Use >/dev/null 2>&1 instead of just 2>/dev/null when sourcing
master-link.sh and calling chain_add_block, mesh_init, peer_add,
factory_trust_peer, and gossip_sync to prevent p2p-mesh.sh usage
text and block hashes from corrupting CGI JSON responses.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 06:38:11 +01:00

57 lines
1.3 KiB
Bash

#!/bin/sh
# Master-Link API - Approve/reject pending peer
# POST /api/master-link/approve
# Auth: Local only (127.0.0.1 or LuCI session)
echo "Content-Type: application/json"
echo "Access-Control-Allow-Origin: *"
echo "Access-Control-Allow-Methods: POST, OPTIONS"
echo "Access-Control-Allow-Headers: Content-Type"
echo ""
# Handle CORS preflight
if [ "$REQUEST_METHOD" = "OPTIONS" ]; then
exit 0
fi
if [ "$REQUEST_METHOD" != "POST" ]; then
echo '{"error":"method_not_allowed"}'
exit 0
fi
# Load library
. /usr/lib/secubox/master-link.sh >/dev/null 2>&1
# Auth check - local only
if ! ml_check_local_auth; then
echo '{"error":"unauthorized","message":"Approval requires local access"}'
exit 0
fi
# Read POST body
read -r input
fingerprint=$(echo "$input" | jsonfilter -e '@.fingerprint' 2>/dev/null)
action=$(echo "$input" | jsonfilter -e '@.action' 2>/dev/null)
reason=$(echo "$input" | jsonfilter -e '@.reason' 2>/dev/null)
if [ -z "$fingerprint" ] || [ -z "$action" ]; then
echo '{"error":"missing_fields","required":["fingerprint","action"]}'
exit 0
fi
case "$action" in
approve)
ml_join_approve "$fingerprint"
;;
reject)
ml_join_reject "$fingerprint" "$reason"
;;
promote)
ml_promote_to_submaster "$fingerprint"
;;
*)
echo '{"error":"invalid_action","valid":["approve","reject","promote"]}'
;;
esac