&1", $output, $returnVar); return $returnVar === 0; } // Handler Operasi POST (Buat Akun & Hapus Akun) if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; if (file_exists($configFile)) { $jsonContent = file_get_contents($configFile); $config = json_decode($jsonContent, true); if ($config && isset($config['inbounds'][0]['settings']['clients'])) { // 1. Aksi: Buat Akun Baru if ($action === 'create') { $rawName = trim($_POST['username'] ?? ''); $accountName = preg_replace('/[^a-zA-Z0-9_-]/', '', $rawName); if (empty($accountName)) { $accountName = "user_" . substr(md5(uniqid()), 0, 5); } $password = !empty($_POST['password']) ? trim($_POST['password']) : bin2hex(random_bytes(8)); $isExist = false; foreach ($config['inbounds'][0]['settings']['clients'] as $client) { if ($client['password'] === $password) { $isExist = true; break; } } if (!$isExist) { // Simpan objek client (beserta tag remark nama akun) $config['inbounds'][0]['settings']['clients'][] = [ 'password' => $password, 'email' => $accountName ]; if (file_put_contents($configFile, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES))) { if (restartXray($output)) { $encodedPath = urlencode("/trojan-ws"); $accountLink = "trojan://{$password}@{$domain}:443?security=tls&sni={$domain}&type=ws&host={$domain}&path={$encodedPath}#{$accountName}"; $message = "
Akun " . htmlspecialchars($accountName) . " berhasil dibuat dan Xray aktif!
"; } else { $message = "
Gagal me-restart Xray: " . htmlspecialchars(implode(" ", $output)) . "
"; } } else { $message = "
Gagal menulis file config.json. Periksa permission file.
"; } } else { $message = "
Password tersebut sudah digunakan pada akun lain.
"; } } // 2. Aksi: Hapus Akun elseif ($action === 'delete') { $targetPassword = $_POST['target_password'] ?? ''; $updatedClients = []; $found = false; foreach ($config['inbounds'][0]['settings']['clients'] as $client) { if ($client['password'] === $targetPassword) { $found = true; } else { $updatedClients[] = $client; } } if ($found) { $config['inbounds'][0]['settings']['clients'] = array_values($updatedClients); if (file_put_contents($configFile, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES))) { if (restartXray($output)) { $message = "
Akun berhasil dihapus dan Xray di-reload!
"; } else { $message = "
Akun terhapus tetapi gagal reload Xray: " . htmlspecialchars(implode(" ", $output)) . "
"; } } } } } else { $message = "
Format JSON tidak valid atau struktur inbound salah.
"; } } else { $message = "
File config.json tidak ditemukan di {$configFile}.
"; } } // Ambil daftar akun aktif dari file konfigurasi $activeClients = []; if (file_exists($configFile)) { $currentJson = json_decode(file_get_contents($configFile), true); $activeClients = $currentJson['inbounds'][0]['settings']['clients'] ?? []; } ?> Trojan WS Account Generator

Trojan WS Generator

Server Host:

Akun Berhasil Dibuat:

Scan QR menggunakan v2rayNG / Nekobox / Matsuri

Daftar Akun Terdaftar ()

Nama / Remark Password Aksi
Belum ada akun terdaftar.