<?php
/** 
 * EVP - Blacklist Monitor Scheduler
 * This file linked to scheduler.opt.php
 **/
// Set script to run in the background
ignore_user_abort(true);
set_time_limit(0);
require_once '../../config.php';

if (($ext_server == 'false') && ($blacklist_check == 'false')) {
    $log->system_debug('External Blacklist monitor scheduler is disabled.');
} else {
    // URL of the script to be executed
    $url = $s_url . '/lib/bl_monitor/ext_bl_monitor.php';

    // API key for security
    $api_key = $apiKey_opt;

    // Check if API key exists
    if (empty($api_key)) {
        $log->system_debug('External Blacklist Monitor API key is invalid.');
        die();
    }

    // Log script execution
    $log->system_debug('External Blacklist Monitor Scheduler Started.');

    // Log the URL being accessed
    $log->system_debug('Accessing URL: ' . $url);

    // cURL initialization
    $ch = curl_init($url);

    // Set cURL options
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, array());
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'API-Key: ' . $api_key // Ensure correct case for header name
    ));
    curl_setopt($ch, CURLOPT_TIMEOUT, 300); // Increase timeout to 300 seconds

    // Execute cURL request
    $response = curl_exec($ch);

    // Check for errors
    if (curl_errno($ch)) {
        $error_msg = curl_error($ch);
        $log->system_debug('cURL error: ' . $error_msg);
    } else {
        $log->system_debug('cURL response: ' . $response);
    }

    // Close cURL session


}

?>