secubox-openwrt/package/secubox/secubox-mesh/files/usr/libexec/rpcd/luci.secubox-mesh
CyberMind-FR cd6af3edff feat(secubox-mesh): Add OpenWrt mesh daemon with topology management
Port secuboxd from Debian/Go to OpenWrt shell implementation:
- secuboxd daemon with Unix control socket at /var/run/secuboxd/topo.sock
- secuboxctl CLI compatible with Debian version interface
- Mesh libraries: topology, discovery, election, telemetry, control
- Mesh gate election with weighted scoring (uptime, peers, CPU, memory, role)
- mDNS service discovery (_secubox._udp.local) via umdns
- DID integration via mirrornet identity library
- RPCD handler with 11 ubus methods for LuCI integration
- procd init script with respawn and network triggers
- UCI config sections: mesh, node, telemetry, discovery

Fixes subprocess state access for socat handler by saving daemon state to file.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-26 06:27:45 +01:00

151 lines
3.4 KiB
Bash
Executable File

#!/bin/sh
# SecuBox Mesh RPCD Handler
# Exposes mesh daemon commands via ubus
# CyberMind — SecuBox — 2026
. /lib/functions.sh
. /usr/share/libubox/jshn.sh
SOCKET="/var/run/secuboxd/topo.sock"
# Send command to daemon
_send_cmd() {
local cmd="$1"
if [ ! -S "$SOCKET" ]; then
echo '{"error":"Daemon not running"}'
return 1
fi
if command -v socat >/dev/null 2>&1; then
echo "$cmd" | socat - "UNIX-CONNECT:$SOCKET" 2>/dev/null
else
echo '{"error":"socat not available"}'
return 1
fi
}
# List available methods
case_list() {
cat <<'EOF'
{
"status": {},
"peers": {},
"topology": {},
"nodes": {},
"node_info": {},
"node_rotate": {},
"telemetry": {},
"ping": {},
"get_config": {},
"set_config": { "role": "string", "beacon_interval": "number" },
"restart": {}
}
EOF
}
# Call method
case_call() {
local method="$1"
case "$method" in
status)
_send_cmd "mesh.status"
;;
peers)
_send_cmd "mesh.peers"
;;
topology)
_send_cmd "mesh.topology"
;;
nodes)
_send_cmd "mesh.nodes"
;;
node_info)
_send_cmd "node.info"
;;
node_rotate)
_send_cmd "node.rotate"
;;
telemetry)
_send_cmd "telemetry.latest"
;;
ping)
local response
response=$(_send_cmd "ping")
if echo "$response" | grep -q '"pong":true'; then
json_init
json_add_boolean running 1
json_dump
else
json_init
json_add_boolean running 0
json_add_string error "Daemon not responding"
json_dump
fi
;;
get_config)
json_init
config_load secubox
local enabled role subnet beacon_interval
config_get_bool enabled mesh enabled 1
config_get role mesh role "edge"
config_get subnet mesh subnet "10.42.0.0/16"
config_get beacon_interval mesh beacon_interval "30"
json_add_boolean enabled "$enabled"
json_add_string role "$role"
json_add_string subnet "$subnet"
json_add_int beacon_interval "$beacon_interval"
json_dump
;;
set_config)
read -r input
local role beacon_interval
json_load "$input"
json_get_var role role
json_get_var beacon_interval beacon_interval
[ -n "$role" ] && uci set secubox.mesh.role="$role"
[ -n "$beacon_interval" ] && uci set secubox.mesh.beacon_interval="$beacon_interval"
uci commit secubox
json_init
json_add_boolean success 1
json_dump
;;
restart)
/etc/init.d/secuboxd restart >/dev/null 2>&1
json_init
json_add_boolean success 1
json_dump
;;
*)
json_init
json_add_string error "Unknown method: $method"
json_dump
return 1
;;
esac
}
# Main dispatcher
case "$1" in
list)
case_list
;;
call)
case_call "$2"
;;
*)
echo '{"error":"Invalid command"}'
exit 1
;;
esac