// --- FLAREFOX 2FA TERMINAL BACKEND SİSTEMİ --- add_action('wp_ajax_ff_system', 'flarefox_backend_handler'); add_action('wp_ajax_nopriv_ff_system', 'flarefox_backend_handler'); function flarefox_backend_handler() { $action_type = isset($_POST['req_type']) ? sanitize_text_field($_POST['req_type']) : ''; $keys = get_option('flarefox_keys', []); $logs = get_option('flarefox_logs', []); // 1. Verileri Getir (Admin Paneli İçin) if ($action_type === 'get_data') { wp_send_json(['keys' => $keys, 'logs' => $logs]); } // 2. Yeni Anahtar Üret ve Kaydet if ($action_type === 'generate_keys') { $new_keys = json_decode(stripslashes($_POST['keys']), true); $keys = array_merge($new_keys, $keys); // Yenileri en başa ekle update_option('flarefox_keys', $keys); array_unshift($logs, [ 'date' => current_time('d.m.Y H:i'), 'type' => 'Admin İşlemi', 'detail' => count($new_keys) . ' adet yeni anahtar üretildi.', 'status' => 'info' ]); update_option('flarefox_logs', array_slice($logs, 0, 100)); // Son 100 logu tut wp_send_json_success(); } // 3. Anahtar Sil if ($action_type === 'delete_key') { $id = intval($_POST['id']); $keys = array_filter($keys, function($k) use ($id) { return $k['id'] != $id; }); update_option('flarefox_keys', array_values($keys)); wp_send_json_success(); } // 4. Cihaz Kilidini Sıfırla if ($action_type === 'reset_device') { $id = intval($_POST['id']); foreach ($keys as &$k) { if ($k['id'] == $id) { $k['ip'] = null; $k['os'] = null; if ($k['status'] !== 'expired') $k['status'] = 'pending'; array_unshift($logs, [ 'date' => current_time('d.m.Y H:i'), 'type' => 'Cihaz Sıfırlama', 'detail' => $k['code'] . ' için cihaz kilidi manuel olarak kaldırıldı.', 'status' => 'warning' ]); break; } } update_option('flarefox_keys', $keys); update_option('flarefox_logs', array_slice($logs, 0, 100)); wp_send_json_success(); } // 5. Müşteri Terminalden Kod Sorguladığında if ($action_type === 'check_code') { $access_code = sanitize_text_field($_POST['code']); $user_ip = $_SERVER['REMOTE_ADDR']; $user_os = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); // Cihaz ve tarayıcı bilgisini kısaltma $os_short = "Cihaz"; if(strpos($user_os, 'Windows') !== false) $os_short = 'Windows'; elseif(strpos($user_os, 'Mac') !== false) $os_short = 'MacOS'; elseif(strpos($user_os, 'iPhone') !== false || strpos($user_os, 'iPad') !== false) $os_short = 'iOS'; elseif(strpos($user_os, 'Android') !== false) $os_short = 'Android'; $found = false; $response = ['error' => 'Geçersiz veya hatalı erişim kodu.']; foreach ($keys as &$k) { if ($k['code'] === $access_code) { $found = true; if ($k['status'] === 'expired') { $response = ['error' => 'Bu anahtarın kullanım süresi dolmuştur.']; array_unshift($logs, ['date' => current_time('d.m.Y H:i'), 'type' => 'Hatalı Giriş', 'detail' => $k['code'] . ' (Süresi Dolmuş) ile giriş denendi.', 'status' => 'error']); break; } if ($k['status'] === 'pending') { // İlk Kullanım: IP'ye kilitle (Aktif üyeliği ezmemek için sadece pending durumunda kilitler) $k['status'] = 'active'; $k['ip'] = $user_ip; $k['os'] = $os_short; $k['used'] = 0; array_unshift($logs, ['date' => current_time('d.m.Y H:i'), 'type' => 'Anahtar Aktivasyonu', 'detail' => $k['code'] . ' kodlu anahtar ' . $user_ip . ' IPsine kilitlendi.', 'status' => 'success']); // Şimdilik sistem rastgele 6 haneli kod üretiyor. İleride ChatGPT API buraya bağlanacak. $response = ['code' => rand(100000, 999999)]; break; } if ($k['status'] === 'active') { if ($k['ip'] === $user_ip) { array_unshift($logs, ['date' => current_time('d.m.Y H:i'), 'type' => 'Anahtar Kullanımı', 'detail' => $k['code'] . ' başarıyla kullanıldı.', 'status' => 'success']); $response = ['code' => rand(100000, 999999)]; } else { array_unshift($logs, ['date' => current_time('d.m.Y H:i'), 'type' => 'Güvenlik İhlali', 'detail' => $k['code'] . ' farklı bir IP ('.$user_ip.') üzerinden denendi. Engellendi.', 'status' => 'warning']); $response = ['error' => 'Cihaz kilidi aktif. Bu kod cihazınıza tanımlanmıştır, farklı bir cihazda veya ağda kullanılamaz.']; } break; } } } if ($found) { update_option('flarefox_keys', $keys); update_option('flarefox_logs', array_slice($logs, 0, 100)); } else { array_unshift($logs, ['date' => current_time('d.m.Y H:i'), 'type' => 'Hatalı Giriş', 'detail' => 'Bilinmeyen kod denemesi: ' . $access_code, 'status' => 'error']); update_option('flarefox_logs', array_slice($logs, 0, 100)); } wp_send_json($response); } wp_die(); }