export default { async fetch(request, env, ctx) { // 1. Mengizinkan CORS (Penting agar tidak diblokir browser) if (request.method === "OPTIONS") { return new Response(null, { headers: { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "POST, OPTIONS", "Access-Control-Allow-Headers": "Content-Type" } }); } if (request.method === 'POST') { try { const body = await request.json(); // --- MENGAMBIL TOKEN & ID DARI ENV --- const botToken = env.TG_BOT_TOKEN; const chatId = env.TG_CHAT_ID; // Cek apakah ENV sudah disetting if (!botToken || !chatId) { return new Response("Error: ENV Variables belum disetting", { status: 500, headers: { "Access-Control-Allow-Origin": "*" } }); } // Ambil IP dan Negara otomatis dari Cloudflare const ip = request.headers.get('cf-connecting-ip') || 'Unknown'; const country = request.headers.get('cf-ipcountry') || 'Unknown'; const ua = request.headers.get('user-agent') || body.ua || 'Unknown'; const pathInfo = body.path || '/dashboard'; // --- LOGIKA PEMILIHAN DUA PANEL --- let alertTitle = "🚨 Akses Admin Panel Terdeteksi! 🚨"; // Deteksi Panel AList (path /@manage atau subpath pengaturannya) if (pathInfo.startsWith('/@manage') || pathInfo.includes('@manage') || body.panel === 'alist') { alertTitle = "🔴 Akses ALIST Panel Terdeteksi! 🔴"; } const msg = `${alertTitle}\n\n` + `📍 Path: ${pathInfo}\n` + `🌐 IP: ${ip}\n` + `🌍 Negara: ${country}\n` + `📱 User Agent: ${ua}`; const tgUrl = `https://api.telegram.org/bot${botToken}/sendMessage`; // Kirim ke Telegram di background ctx.waitUntil( fetch(tgUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ chat_id: chatId, text: msg, parse_mode: 'HTML' }) }) ); return new Response(JSON.stringify({ success: true }), { headers: { "Access-Control-Allow-Origin": "*", "Content-Type": "application/json" } }); } catch (err) { return new Response("Error processing request", { status: 500, headers: { "Access-Control-Allow-Origin": "*" } }); } } // Jika diakses via browser GET biasa return new Response("Panel Logger API Active", { headers: { "Access-Control-Allow-Origin": "*" } }); } }; alice