#!/bin/bash
python3 - <<'PYEOF'
import socket, json
p = "/run/defence360agent/non_root_simple_rpc.sock"
def probe(payload, label):
    try:
        s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        s.settimeout(2)
        s.connect(p)
        s.sendall(payload)
        try:
            data = s.recv(1024)
            print(label, "=>", repr(data[:1024]))
        except Exception as e:
            print(label, "recv:", type(e).__name__, e)
        s.close()
    except Exception as e:
        print(label, "FAIL:", type(e).__name__, e)

tests = [
    ('{"command":["ping"],"params":{}}', "cmd-ping"),
    ('{"command":["help"],"params":{}}', "cmd-help"),
    ('{"command":["version"],"params":{}}', "cmd-version"),
    ('{"command":["get_version"],"params":{}}', "cmd-get_version"),
    ('{"command":["status"],"params":{}}', "cmd-status"),
    ('{"command":["info"],"params":{}}', "cmd-info"),
    ('{"command":["methods"],"params":{}}', "cmd-methods"),
    ('{"command":["list_methods"],"params":{}}', "cmd-list_methods"),
    ('{"command":["get_methods"],"params":{}}', "cmd-get_methods"),
    ('{"command":["__methods__"],"params":{}}', "cmd-__methods__"),
    ('{"command":["scan"],"params":{}}', "cmd-scan"),
    ('{"command":["get_config"],"params":{}}', "cmd-get_config"),
    ('{"command":["get_status"],"params":{}}', "cmd-get_status"),
    ('{"command":["list"],"params":{}}', "cmd-list"),
    ('{"command":["query"],"params":{}}', "cmd-query"),
    ('{"command":["add"],"params":{}}', "cmd-add"),
    ('{"command":["remove"],"params":{}}', "cmd-remove"),
    ('{"command":["get"],"params":{}}', "cmd-get"),
    ('{"command":["set"],"params":{}}', "cmd-set"),
    ('{"command":["exec"],"params":{}}', "cmd-exec"),
    ('{"command":["run"],"params":{}}', "cmd-run"),
    ('{"command":["command"],"params":{}}', "cmd-command"),
    ('{"command":["whoami"],"params":{}}', "cmd-whoami"),
    ('{"command":["id"],"params":{}}', "cmd-id"),
]
for payload, label in tests:
    probe(payload.encode(), label)
PYEOF
