38790-vm/api/bridge_control.php
Flatlogic Bot 3f421e9a53 Good Versi
2026-02-26 19:50:11 +00:00

48 lines
1.5 KiB
PHP

<?php
header('Content-Type: application/json');
session_start();
require_once __DIR__ . '/../db/config.php';
// Authentication check
if (!isset($_SESSION['user_id'])) {
echo json_encode(['error' => 'Unauthorized']);
exit;
}
$user_id = $_SESSION['user_id'];
$action = $_GET['action'] ?? '';
$username = $_GET['username'] ?? '';
if (empty($username)) {
echo json_encode(['success' => false, 'error' => 'Username required']);
exit;
}
if ($action === 'start') {
// 1. Kill any existing bridge for this user
shell_exec("pkill -f \"node tiktok_bridge.js $username $user_id\"");
// 2. Start new bridge
$cmd = sprintf(
"node %s %s %s %s %s %s %s > /dev/null 2>&1 &",
escapeshellarg(__DIR__ . '/../tiktok_bridge.js'),
escapeshellarg($username),
escapeshellarg(DB_HOST),
escapeshellarg(DB_USER),
escapeshellarg(DB_PASS),
escapeshellarg(DB_NAME),
escapeshellarg($user_id)
);
shell_exec($cmd);
echo json_encode(['success' => true, 'message' => "Bridge started for @$username"]);
} elseif ($action === 'stop') {
shell_exec("pkill -f \"node tiktok_bridge.js $username $user_id\"");
echo json_encode(['success' => true, 'message' => "Bridge stopped for @$username"]);
} elseif ($action === 'status') {
$output = shell_exec("pgrep -f \"node tiktok_bridge.js $username $user_id\"");
echo json_encode(['success' => true, 'running' => !empty($output)]);
} else {
echo json_encode(['success' => false, 'error' => 'Invalid action']);
}