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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/soundstudiopro.com/public_html/ajax_monitor.php
<?php
/**
 * AJAX Monitor - Tracks navigation performance and errors
 * Provides debugging information for AJAX navigation system
 */

session_start();
require_once 'config/database.php';

// Set JSON header
header('Content-Type: application/json');

// Get action
$action = $_POST['action'] ?? '';

switch ($action) {
    case 'log_navigation':
        logNavigation();
        break;
    case 'log_performance':
        logPerformance();
        break;
    case 'get_stats':
        getStats();
        break;
    default:
        echo json_encode(['success' => false, 'error' => 'Invalid action']);
        break;
}

/**
 * Log navigation events
 */
function logNavigation() {
    $fromPage = $_POST['from_page'] ?? '';
    $toPage = $_POST['to_page'] ?? '';
    $method = $_POST['method'] ?? '';
    
    // Log to database if table exists
    try {
        $pdo = getDBConnection();
        if (!$pdo) {
            throw new Exception('Database connection failed');
        }
        
        // Check if ajax_logs table exists
        $stmt = $pdo->query("SHOW TABLES LIKE 'ajax_logs'");
        if ($stmt->rowCount() > 0) {
            $stmt = $pdo->prepare("INSERT INTO ajax_logs (from_page, to_page, method, timestamp, user_id) VALUES (?, ?, ?, NOW(), ?)");
            $stmt->execute([$fromPage, $toPage, $method, $_SESSION['user_id'] ?? null]);
        }
    } catch (Exception $e) {
        // Log to error log if database fails
        error_log("AJAX Monitor DB Error: " . $e->getMessage());
    }
    
    // Also log to file for debugging
    $logEntry = date('Y-m-d H:i:s') . " | Navigation: $fromPage -> $toPage ($method)\n";
    file_put_contents('logs/ajax_navigation.log', $logEntry, FILE_APPEND | LOCK_EX);
    
    echo json_encode(['success' => true]);
}

/**
 * Log performance metrics
 */
function logPerformance() {
    $page = $_POST['page'] ?? '';
    $loadTime = $_POST['load_time'] ?? '';
    $contentSize = $_POST['content_size'] ?? '';
    
    // Log to database if table exists
    try {
        $pdo = getDBConnection();
        if (!$pdo) {
            throw new Exception('Database connection failed');
        }
        
        // Check if ajax_performance table exists
        $stmt = $pdo->query("SHOW TABLES LIKE 'ajax_performance'");
        if ($stmt->rowCount() > 0) {
            $stmt = $pdo->prepare("INSERT INTO ajax_performance (page, load_time, content_size, timestamp) VALUES (?, ?, ?, NOW())");
            $stmt->execute([$page, $loadTime, $contentSize]);
        }
    } catch (Exception $e) {
        // Log to error log if database fails
        error_log("AJAX Monitor DB Error: " . $e->getMessage());
    }
    
    // Also log to file for debugging
    $logEntry = date('Y-m-d H:i:s') . " | Performance: $page | Load: {$loadTime}ms | Size: {$contentSize} bytes\n";
    file_put_contents('logs/ajax_performance.log', $logEntry, FILE_APPEND | LOCK_EX);
    
    echo json_encode(['success' => true]);
}

/**
 * Get navigation statistics
 */
function getStats() {
    try {
        $pdo = getDBConnection();
        if (!$pdo) {
            throw new Exception('Database connection failed');
        }
        
        $stats = [
            'total_navigations' => 0,
            'total_errors' => 0,
            'avg_load_time' => 0,
            'recent_navigations' => []
        ];
        
        // Check if ajax_logs table exists
        $stmt = $pdo->query("SHOW TABLES LIKE 'ajax_logs'");
        if ($stmt->rowCount() > 0) {
            // Get total navigations
            $stmt = $pdo->query("SELECT COUNT(*) FROM ajax_logs");
            $stats['total_navigations'] = $stmt->fetchColumn();
            
            // Get recent navigations
            $stmt = $pdo->query("SELECT * FROM ajax_logs ORDER BY timestamp DESC LIMIT 10");
            $stats['recent_navigations'] = $stmt->fetchAll(PDO::FETCH_ASSOC);
        }
        
        // Check if ajax_performance table exists
        $stmt = $pdo->query("SHOW TABLES LIKE 'ajax_performance'");
        if ($stmt->rowCount() > 0) {
            // Get average load time
            $stmt = $pdo->query("SELECT AVG(load_time) FROM ajax_performance");
            $stats['avg_load_time'] = round($stmt->fetchColumn(), 2);
        }
        
        echo json_encode(['success' => true, 'stats' => $stats]);
        
    } catch (Exception $e) {
        echo json_encode(['success' => false, 'error' => $e->getMessage()]);
    }
}


/**
 * Create monitoring tables if they don't exist
 */
function createMonitoringTables() {
    try {
        $pdo = getDBConnection();
        if (!$pdo) {
            throw new Exception('Database connection failed');
        }
        
        // Create ajax_logs table
        $pdo->exec("
            CREATE TABLE IF NOT EXISTS ajax_logs (
                id INT AUTO_INCREMENT PRIMARY KEY,
                from_page VARCHAR(255),
                to_page VARCHAR(255),
                method VARCHAR(50),
                timestamp DATETIME,
                user_id INT,
                INDEX idx_timestamp (timestamp),
                INDEX idx_user (user_id)
            )
        ");
        
        // Create ajax_performance table
        $pdo->exec("
            CREATE TABLE IF NOT EXISTS ajax_performance (
                id INT AUTO_INCREMENT PRIMARY KEY,
                page VARCHAR(255),
                load_time DECIMAL(10,2),
                content_size INT,
                timestamp DATETIME,
                INDEX idx_page (page),
                INDEX idx_timestamp (timestamp)
            )
        ");
        
        return true;
    } catch (Exception $e) {
        error_log("Failed to create monitoring tables: " . $e->getMessage());
        return false;
    }
}

// Create tables if this is the first run
if (!file_exists('logs/ajax_navigation.log')) {
    // Create logs directory
    if (!is_dir('logs')) {
        mkdir('logs', 0755, true);
    }
    
    // Create log files
    file_put_contents('logs/ajax_navigation.log', "AJAX Navigation Log\n");
    file_put_contents('logs/ajax_performance.log', "AJAX Performance Log\n");
    
    // Try to create monitoring tables
    createMonitoringTables();
}
?>

CasperSecurity Mini