T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/soundstudiopro.com/private_html/utils/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/soundstudiopro.com/private_html/utils/auto_fix_tracks.php
<?php
require_once 'config/database.php';

$pdo = getDBConnection();

echo "<h2>Auto-Fix Processing Tracks</h2>";

// Get all tracks that are stuck in processing status
$stmt = $pdo->query("
    SELECT * FROM music_tracks 
    WHERE status = 'processing' 
    ORDER BY created_at DESC
");

$processing_tracks = $stmt->fetchAll();

echo "<p>Found " . count($processing_tracks) . " tracks in processing status</p>";

$fixed_count = 0;

foreach ($processing_tracks as $track) {
    echo "<h3>Checking track: " . htmlspecialchars($track['title']) . " (ID: " . $track['id'] . ")</h3>";
    echo "<p>Task ID: " . $track['task_id'] . "</p>";
    
    // Check if there's a result file for this task
    $result_file = "task_results/{$track['task_id']}.json";
    
    if (file_exists($result_file)) {
        echo "<p style='color: green;'>✅ Found result file!</p>";
        $result_data = json_decode(file_get_contents($result_file), true);
        
        if ($result_data && isset($result_data['data']['callbackType']) && $result_data['data']['callbackType'] === 'complete') {
            $audio_data = $result_data['data']['data'][0] ?? null;
            if ($audio_data && isset($audio_data['audio_url'])) {
                $audio_url = $audio_data['audio_url'];
                $duration = $audio_data['duration'] ?? 30;
                
                // Extract title from API response (check all items for title)
                $title = null;
                if (isset($result_data['data']['data']) && is_array($result_data['data']['data'])) {
                    foreach ($result_data['data']['data'] as $item) {
                        if (isset($item['title']) && !empty($item['title']) && trim($item['title']) !== '') {
                            $title = trim($item['title']);
                            break;
                        }
                    }
                }
                
                // Extract tags from API response
                $tags = null;
                if (isset($audio_data['tags']) && !empty($audio_data['tags'])) {
                    $tags = is_array($audio_data['tags']) ? implode('; ', $audio_data['tags']) : $audio_data['tags'];
                }
                
                // Extract model_name from API response
                $modelName = $audio_data['model_name'] ?? null;
                
                // Update the track to complete with title, tags, and model_name
                updateMusicTrack($track['task_id'], 'complete', $audio_url, null, null, json_encode($result_data), $duration, $title, $tags, $modelName);
                
                echo "<p style='color: green;'>✅ AUTO-FIXED: Track " . $track['id'] . " set to COMPLETE!</p>";
                echo "<p>Audio URL: $audio_url</p>";
                echo "<p>Duration: $duration seconds</p>";
                if ($title) {
                    echo "<p>Title: " . htmlspecialchars($title) . "</p>";
                }
                $fixed_count++;
            }
        } else {
            echo "<p style='color: orange;'>⚠️ Result file exists but not complete</p>";
        }
    } else {
        echo "<p style='color: red;'>❌ No result file found for task: " . $track['task_id'] . "</p>";
        
        // Check if this task was actually sent to API.Box
        $api_key = '63edba40620216c5aa2c04240ac41dbd';
        $task_id = $track['task_id'];
        
        // Try to check if this task exists in API.Box
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.api.box/api/v1/status/$task_id");
        curl_setopt($ch, CURLOPT_HTTPGET, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Authorization: Bearer ' . $api_key,
            'Content-Type: application/json'
        ]);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        
        $response = curl_exec($ch);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        
        echo "<p>API.Box check: HTTP $http_code</p>";
        
        // If the task doesn't exist in API.Box, mark it as failed
        if ($http_code === 404) {
            updateMusicTrack($track['task_id'], 'failed');
            echo "<p style='color: red;'>❌ Task not found in API.Box - marked as FAILED</p>";
        }
    }
    
    echo "<hr>";
}

echo "<h3>✅ Processing Tracks Fixed: $fixed_count</h3>";

// PART 2: Fix completed tracks with missing titles
echo "<h2>🔧 Fixing Missing Titles on Completed Tracks</h2>";

// Only fix titles that haven't been user-modified
$stmt = $pdo->query("
    SELECT id, task_id, title FROM music_tracks 
    WHERE status = 'complete' 
    AND (title IS NULL OR title = '' OR title = 'Untitled Track' OR title = 'Generated Track')
    AND (title_user_modified = 0 OR title_user_modified IS NULL)
    ORDER BY created_at DESC
    LIMIT 100
");

$missing_title_tracks = $stmt->fetchAll();
$title_fixed_count = 0;

echo "<p>Found " . count($missing_title_tracks) . " completed tracks with missing titles</p>";

foreach ($missing_title_tracks as $track) {
    $result_file = "task_results/{$track['task_id']}.json";
    
    if (file_exists($result_file)) {
        $result_data = json_decode(file_get_contents($result_file), true);
        
        // Extract title from API response
        $title = null;
        if (isset($result_data['data']['data']) && is_array($result_data['data']['data'])) {
            foreach ($result_data['data']['data'] as $item) {
                if (isset($item['title']) && !empty($item['title']) && trim($item['title']) !== '') {
                    $title = trim($item['title']);
                    break;
                }
            }
        }
        
        if ($title) {
            // Update track with the extracted title
            $update_stmt = $pdo->prepare("UPDATE music_tracks SET title = ?, updated_at = NOW() WHERE id = ?");
            if ($update_stmt->execute([$title, $track['id']])) {
                echo "<p style='color: green;'>✅ Fixed title for Track ID {$track['id']}: " . htmlspecialchars($title) . "</p>";
                $title_fixed_count++;
            }
        }
    }
}

echo "<h3>✅ Title Fixes Complete!</h3>";
echo "<p>Fixed $title_fixed_count track titles</p>";
echo "<p>Total fixes this run: " . ($fixed_count + $title_fixed_count) . "</p>";

// Set up a cron job suggestion
echo "<h3>🔄 To make this permanent, add this to your crontab:</h3>";
echo "<p><code>*/5 * * * * php /home/gositeme/domains/soundstudiopro.com/public_html/auto_fix_tracks.php > /dev/null 2>&1</code></p>";
echo "<p>This will run every 5 minutes to automatically fix any stuck tracks.</p>";
?> 

CasperSecurity Mini