From 4a6ca417ad8354620cde4f2e09e27228b71f4619 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Sun, 5 Jul 2026 23:31:51 +0300 Subject: [PATCH] Update: 2026-07-05 23:31:51 --- .../marketing_engine/client_bot_template.py | 10 ++++++- backend/marketing_engine/social_worker.php | 27 +++++++++++++++++++ backend/schema_primary.sql | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/backend/marketing_engine/client_bot_template.py b/backend/marketing_engine/client_bot_template.py index 6ba75c57..0df0c68f 100644 --- a/backend/marketing_engine/client_bot_template.py +++ b/backend/marketing_engine/client_bot_template.py @@ -24,6 +24,8 @@ import requests SERVER_URL = "http://jordan-siro.intaleqapp.com/backend/marketing_engine/social_worker.php" BOT_TOKEN = "YOUR_SECRET_BOT_TOKEN" # Must match headers in social_worker.php PLATFORM = "facebook" # 'facebook' or 'telegram' +ACCOUNT_ID = None # Set to a specific integer if manual mapping is preferred +DEVICE_ID = None # e.g. "a1b2c3d4" - Recommended: The unique Android device ID for auto Plug & Play binding CHECK_INTERVAL_SECONDS = 60 # Cooldown between checking for new tasks headers = { @@ -105,7 +107,13 @@ def report_status(action, params): def process_task(): print("[*] Checking for pending tasks...") try: - res = requests.get(f"{SERVER_URL}?action=get_task&platform={PLATFORM}", headers=headers, timeout=10) + url = f"{SERVER_URL}?action=get_task&platform={PLATFORM}" + if ACCOUNT_ID: + url += f"&account_id={ACCOUNT_ID}" + elif DEVICE_ID: + url += f"&device_id={DEVICE_ID}" + + res = requests.get(url, headers=headers, timeout=10) response_data = res.json() except Exception as e: print(f"[-] Connection failed: {e}") diff --git a/backend/marketing_engine/social_worker.php b/backend/marketing_engine/social_worker.php index 3f0cd858..b454ea7b 100644 --- a/backend/marketing_engine/social_worker.php +++ b/backend/marketing_engine/social_worker.php @@ -27,6 +27,33 @@ try { // The bot asks for a task to do $platform = $_GET['platform'] ?? 'facebook'; $requestedAccountId = $_GET['account_id'] ?? null; + $deviceId = $_GET['device_id'] ?? null; + + // Automatic Plug & Play Device Binding + if ($deviceId) { + $stmtDev = $con->prepare("SELECT id FROM social_accounts WHERE device_id = ?"); + $stmtDev->execute([$deviceId]); + $acc = $stmtDev->fetch(PDO::FETCH_ASSOC); + if ($acc) { + $requestedAccountId = $acc['id']; + } else { + require_once __DIR__ . '/account_manager.php'; + $am = new AccountManager(); + // Find an account that doesn't have a device_id yet + $stmtFind = $con->prepare("SELECT id FROM social_accounts WHERE platform = ? AND device_id IS NULL AND status = 'active' LIMIT 1"); + $stmtFind->execute([$platform]); + $newAcc = $stmtFind->fetch(PDO::FETCH_ASSOC); + + if ($newAcc) { + $requestedAccountId = $newAcc['id']; + $updateDev = $con->prepare("UPDATE social_accounts SET device_id = ? WHERE id = ?"); + $updateDev->execute([$deviceId, $requestedAccountId]); + } else { + echo json_encode(['status' => 'error', 'message' => 'No available unassigned accounts for this new device']); + break; + } + } + } // Find a pending task that is scheduled for now or earlier if ($requestedAccountId) { diff --git a/backend/schema_primary.sql b/backend/schema_primary.sql index 781c3554..5cdfcc2d 100644 --- a/backend/schema_primary.sql +++ b/backend/schema_primary.sql @@ -2087,6 +2087,7 @@ CREATE TABLE IF NOT EXISTS `social_accounts` ( `proxy_port` INT NULL, `proxy_username` VARCHAR(100) NULL, `proxy_password` VARCHAR(100) NULL, + `device_id` VARCHAR(255) NULL UNIQUE, `last_active` DATETIME NULL, `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP, `updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP