41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
require_once __DIR__ . '/../db/config.php';
|
|
|
|
$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\"");
|
|
|
|
// 2. Start new bridge
|
|
$cmd = sprintf(
|
|
"node %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)
|
|
);
|
|
|
|
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\"");
|
|
echo json_encode(['success' => true, 'message' => "Bridge stopped for @$username"]);
|
|
} elseif ($action === 'status') {
|
|
$output = shell_exec("pgrep -f \"node tiktok_bridge.js $username\"");
|
|
echo json_encode(['success' => true, 'running' => !empty($output)]);
|
|
} else {
|
|
echo json_encode(['success' => false, 'error' => 'Invalid action']);
|
|
}
|
|
|