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/monitor_and_fix.php
<?php
/**
 * Monitor and Fix Stuck Tracks
 * 
 * This script monitors for tracks stuck in processing status and automatically fixes them.
 * Run this script periodically (every 5-10 minutes) to ensure tracks are properly updated.
 * 
 * Usage: php monitor_and_fix.php
 */

require_once 'config/database.php';

$pdo = getDBConnection();

// Log file for monitoring
$logFile = 'monitor_log.txt';
$timestamp = date('Y-m-d H:i:s');

// 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();

$logEntry = "[$timestamp] Monitor run - Found " . count($processing_tracks) . " processing tracks\n";
file_put_contents($logFile, $logEntry, FILE_APPEND | LOCK_EX);

$fixed_count = 0;
$failed_count = 0;

foreach ($processing_tracks as $track) {
    $task_id = $track['task_id'];
    $result_file = "task_results/{$task_id}.json";
    
    if (file_exists($result_file)) {
        $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;
                
                // Update the track to complete
                updateMusicTrack($task_id, 'complete', $audio_url, null, null, json_encode($result_data), $duration);
                
                $logEntry = "[$timestamp] ✅ Fixed track {$track['id']} ({$track['title']}) - Set to COMPLETE\n";
                file_put_contents($logFile, $logEntry, FILE_APPEND | LOCK_EX);
                $fixed_count++;
            }
        }
    } else {
        // Check if this task was actually sent to API.Box
        $api_key = '63edba40620216c5aa2c04240ac41dbd';
        
        $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);
        
        // If the task doesn't exist in API.Box, mark it as failed
        if ($http_code === 404) {
            updateMusicTrack($task_id, 'failed');
            $logEntry = "[$timestamp] ❌ Marked track {$track['id']} ({$track['title']}) as FAILED - Not found in API.Box\n";
            file_put_contents($logFile, $logEntry, FILE_APPEND | LOCK_EX);
            $failed_count++;
        }
    }
}

$summary = "[$timestamp] Monitor complete - Fixed: $fixed_count, Failed: $failed_count\n";
file_put_contents($logFile, $summary, FILE_APPEND | LOCK_EX);

// Keep log file manageable (last 1000 lines)
$logLines = file($logFile);
if (count($logLines) > 1000) {
    $logLines = array_slice($logLines, -1000);
    file_put_contents($logFile, implode('', $logLines));
}

// Output summary for manual runs
if (php_sapi_name() === 'cli' || isset($_GET['output'])) {
    echo "Monitor run completed at $timestamp\n";
    echo "Fixed: $fixed_count tracks\n";
    echo "Failed: $failed_count tracks\n";
    echo "Log: $logFile\n";
}
?> 

CasperSecurity Mini