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/copyright_protection.php
<?php
/**
 * Copyright Protection Utilities
 * 
 * Functions for:
 * - Generating audio file hashes
 * - Creating copyright certificates
 * - Embedding ID3 tags
 */

require_once __DIR__ . '/../config/database.php';

/**
 * Generate SHA-256 hash of audio file
 * 
 * @param string $filePath Path to audio file
 * @return string|false SHA-256 hash or false on failure
 */
function generateAudioHash($filePath) {
    if (!file_exists($filePath)) {
        error_log("Audio file not found for hashing: $filePath");
        return false;
    }
    
    return hash_file('sha256', $filePath);
}

/**
 * Generate copyright hash (combined proof)
 * Combines track ID, audio hash, creation timestamp, and user ID
 * 
 * @param int $trackId Track ID
 * @param string $audioHash SHA-256 hash of audio file
 * @param string $createdAt Creation timestamp
 * @param int $userId User ID
 * @return string SHA-256 hash
 */
function generateCopyrightHash($trackId, $audioHash, $createdAt, $userId) {
    $data = $trackId . '|' . $audioHash . '|' . $createdAt . '|' . $userId;
    return hash('sha256', $data);
}

/**
 * Update track with audio hash and copyright hash
 * 
 * @param string $taskId Task ID
 * @param string $audioHash SHA-256 hash of audio file
 * @return bool Success
 */
function updateTrackHashes($taskId, $audioHash) {
    try {
        $pdo = getDBConnection();
        if (!$pdo) {
            return false;
        }
        
        // Get track info
        $stmt = $pdo->prepare("SELECT id, created_at, user_id FROM music_tracks WHERE task_id = ?");
        $stmt->execute([$taskId]);
        $track = $stmt->fetch(PDO::FETCH_ASSOC);
        
        if (!$track) {
            error_log("Track not found for hash update: $taskId");
            return false;
        }
        
        // Generate copyright hash
        $copyrightHash = generateCopyrightHash(
            $track['id'],
            $audioHash,
            $track['created_at'],
            $track['user_id']
        );
        
        // Update database
        $updateStmt = $pdo->prepare("
            UPDATE music_tracks 
            SET audio_hash = ?, copyright_hash = ? 
            WHERE task_id = ?
        ");
        
        return $updateStmt->execute([$audioHash, $copyrightHash, $taskId]);
        
    } catch (Exception $e) {
        error_log("Error updating track hashes: " . $e->getMessage());
        return false;
    }
}

/**
 * Embed ID3 tags in audio file
 * Requires getID3 library or similar
 * 
 * @param string $filePath Path to audio file
 * @param array $metadata Track metadata (title, artist, copyright, etc.)
 * @return bool Success
 */
function embedID3Tags($filePath, $metadata) {
    if (!file_exists($filePath)) {
        error_log("Audio file not found for ID3 embedding: $filePath");
        return false;
    }
    
    // Check if getID3 library is available
    $getid3Path = __DIR__ . '/../vendor/james-heinrich/getid3/getid3/getid3.php';
    if (file_exists($getid3Path)) {
        require_once $getid3Path;
        require_once __DIR__ . '/../vendor/james-heinrich/getid3/getid3/write.php';
        
        try {
            $getID3 = new getID3;
            $getID3->encoding = 'UTF-8';
            
            $tagwriter = new getid3_writetags;
            $tagwriter->filename = $filePath;
            $tagwriter->tagformats = ['id3v2.3'];
            $tagwriter->overwrite_tags = true;
            $tagwriter->remove_other_tags = false;
            $tagwriter->tag_encoding = 'UTF-8';
            
            // Prepare tags
            $tagData = [
                'title' => [$metadata['title'] ?? 'Untitled Track'],
                'artist' => [$metadata['artist'] ?? 'Unknown Artist'],
                'album' => ['SoundStudioPro'],
                'year' => [date('Y', strtotime($metadata['created_at'] ?? 'now'))],
                'comment' => [$metadata['comment'] ?? ''],
            ];
            
            // Add copyright info
            if (isset($metadata['copyright'])) {
                $tagData['copyright'] = [$metadata['copyright']];
            }
            
            // Add publisher
            $tagData['publisher'] = ['SoundStudioPro'];
            
            // Add unique identifier
            if (isset($metadata['track_id'])) {
                $tagData['track'] = [$metadata['track_id']];
            }
            
            $tagwriter->tag_data = $tagData;
            
            if ($tagwriter->WriteTags()) {
                if (!empty($tagwriter->warnings)) {
                    error_log("ID3 tag warnings: " . implode(', ', $tagwriter->warnings));
                }
                return true;
            } else {
                error_log("ID3 tag write failed: " . implode(', ', $tagwriter->errors));
                return false;
            }
            
        } catch (Exception $e) {
            error_log("ID3 tag embedding error: " . $e->getMessage());
            return false;
        }
    } else {
        // Fallback: Log that ID3 library is not available
        error_log("getID3 library not found. ID3 tags not embedded. Install via: composer require james-heinrich/getid3");
        return false;
    }
}

/**
 * Get copyright certificate data for a track
 * 
 * @param int $trackId Track ID
 * @return array|false Certificate data or false on failure
 */
function getCopyrightCertificate($trackId) {
    try {
        $pdo = getDBConnection();
        if (!$pdo) {
            return false;
        }
        
        $stmt = $pdo->prepare("
            SELECT 
                mt.id,
                mt.title,
                mt.task_id,
                mt.audio_hash,
                mt.copyright_hash,
                mt.created_at,
                mt.user_id,
                u.name as artist_name,
                u.email as artist_email
            FROM music_tracks mt
            JOIN users u ON mt.user_id = u.id
            WHERE mt.id = ?
        ");
        
        $stmt->execute([$trackId]);
        $track = $stmt->fetch(PDO::FETCH_ASSOC);
        
        if (!$track) {
            return false;
        }
        
        return [
            'track_id' => $track['id'],
            'task_id' => $track['task_id'],
            'title' => $track['title'],
            'artist_name' => $track['artist_name'],
            'created_at' => $track['created_at'],
            'audio_hash' => $track['audio_hash'],
            'copyright_hash' => $track['copyright_hash'],
            'certificate_number' => 'SSP-' . str_pad($track['id'], 8, '0', STR_PAD_LEFT) . '-' . substr($track['copyright_hash'] ?? '', 0, 8)
        ];
        
    } catch (Exception $e) {
        error_log("Error getting copyright certificate: " . $e->getMessage());
        return false;
    }
}
?>


CasperSecurity Mini