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/api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/soundstudiopro.com/private_html/api/mark_track_failed.php
<?php
// API endpoint to mark a track as failed (for timeout scenarios)
session_start();
header('Content-Type: application/json');

// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
    echo json_encode([
        'success' => false,
        'message' => 'User not logged in'
    ]);
    exit;
}

$track_id = $_GET['track_id'] ?? $_POST['track_id'] ?? null;

if (!$track_id) {
    echo json_encode([
        'success' => false,
        'message' => 'Track ID required'
    ]);
    exit;
}

try {
    require_once '../config/database.php';
    $pdo = getDBConnection();
    
    // Get track and verify ownership
    $stmt = $pdo->prepare("
        SELECT id, user_id, task_id, title, status, created_at
        FROM music_tracks 
        WHERE id = ? AND user_id = ?
    ");
    $stmt->execute([$track_id, $_SESSION['user_id']]);
    $track = $stmt->fetch(PDO::FETCH_ASSOC);
    
    if (!$track) {
        echo json_encode([
            'success' => false,
            'message' => 'Track not found'
        ]);
        exit;
    }
    
    // Only mark as failed if it's currently processing
    if ($track['status'] !== 'processing') {
        echo json_encode([
            'success' => false,
            'message' => 'Track is not in processing status'
        ]);
        exit;
    }
    
    // Check how long it's been processing
    $created_time = strtotime($track['created_at']);
    $processing_minutes = round((time() - $created_time) / 60, 1);
    
    // Only mark as failed if it's been processing for more than 5 minutes
    if ($processing_minutes < 5) {
        echo json_encode([
            'success' => false,
            'message' => 'Track has not been processing long enough (5 minute minimum)'
        ]);
        exit;
    }
    
    // Check API status first
    $api_key = '63edba40620216c5aa2c04240ac41dbd';
    $task_id = $track['task_id'];
    
    if (!empty($task_id) && $task_id !== 'unknown' && !str_starts_with($task_id, 'temp_') && !str_starts_with($task_id, 'retry_')) {
        $api_url = "https://api.api.box/api/v1/status/$task_id";
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $api_url);
        curl_setopt($ch, CURLOPT_HTTPGET, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Authorization: Bearer ' . $api_key,
            'Content-Type: application/json',
            'User-Agent: SoundStudioPro-Timeout/1.0'
        ]);
        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 ($http_code === 200 && $response) {
            $api_data = json_decode($response, true);
            
            if ($api_data && isset($api_data['status'])) {
                $api_status = $api_data['status'];
                
                if ($api_status === 'failed') {
                    // API says it failed - use that error message
                    $error_msg = $api_data['error'] ?? $api_data['msg'] ?? 'Generation failed';
                    $error_metadata = json_encode([
                        'code' => 531,
                        'msg' => $error_msg,
                        'error_type' => 'generation_failed',
                        'data' => $api_data,
                        'timestamp' => date('Y-m-d H:i:s'),
                        'timeout_marked' => true
                    ]);
                } else {
                    // Still processing in API but taking too long - mark as timeout
                    $error_metadata = json_encode([
                        'code' => 408,
                        'msg' => 'Track generation timed out after 5 minutes',
                        'error_type' => 'timeout',
                        'processing_time_minutes' => $processing_minutes,
                        'timestamp' => date('Y-m-d H:i:s'),
                        'timeout_marked' => true
                    ]);
                }
            } else {
                // API response invalid - mark as timeout
                $error_metadata = json_encode([
                    'code' => 408,
                    'msg' => 'Track generation timed out after 5 minutes',
                    'error_type' => 'timeout',
                    'processing_time_minutes' => $processing_minutes,
                    'timestamp' => date('Y-m-d H:i:s'),
                    'timeout_marked' => true
                ]);
            }
        } else {
            // API check failed - mark as timeout
            $error_metadata = json_encode([
                'code' => 408,
                'msg' => 'Track generation timed out after 5 minutes',
                'error_type' => 'timeout',
                'processing_time_minutes' => $processing_minutes,
                'timestamp' => date('Y-m-d H:i:s'),
                'timeout_marked' => true
            ]);
        }
    } else {
        // No valid task_id - mark as timeout
        $error_metadata = json_encode([
            'code' => 408,
            'msg' => 'Track generation timed out after 5 minutes',
            'error_type' => 'timeout',
            'processing_time_minutes' => $processing_minutes,
            'timestamp' => date('Y-m-d H:i:s'),
            'timeout_marked' => true
        ]);
    }
    
    // Update track to failed
    $stmt = $pdo->prepare("
        UPDATE music_tracks 
        SET status = 'failed', 
            metadata = ?, 
            updated_at = NOW() 
        WHERE id = ?
    ");
    $stmt->execute([$error_metadata, $track_id]);
    
    // Refund credit for timeout
    $stmt = $pdo->prepare("UPDATE users SET credits = credits + 1 WHERE id = ?");
    $stmt->execute([$_SESSION['user_id']]);
    
    // Record refund transaction
    $stmt = $pdo->prepare("
        INSERT INTO credit_transactions (user_id, amount, type, description, created_at) 
        VALUES (?, 1, 'refund', 'Credit refund for timed out track: {$track['title']}', NOW())
    ");
    $stmt->execute([$_SESSION['user_id']]);
    
    echo json_encode([
        'success' => true,
        'message' => 'Track marked as failed due to timeout',
        'processing_time_minutes' => $processing_minutes
    ]);
    
} catch (Exception $e) {
    error_log("Error marking track as failed: " . $e->getMessage());
    echo json_encode([
        'success' => false,
        'message' => 'Internal server error'
    ]);
}
?>


CasperSecurity Mini