<?php

$ip = "192.168.100.254";
$port = "80";
$user = "admin";
$pass = "28251714.";

$url = "http://$ip:$port/ISAPI/AccessControl/AcsEvent/Search?format=json";

$payload = json_encode([
    "AcsEventCond" => [
        "searchID" => "1",
        "searchResultPosition" => 0,
        "maxResults" => 30,
        "startTime" => "2026-03-01T00:00:00-04:00",
        "endTime" => "2026-03-31T23:59:59-04:00"
    ]
], JSON_UNESCAPED_UNICODE);

$ch = curl_init($url);

curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPAUTH => CURLAUTH_DIGEST,
    CURLOPT_USERPWD => "$user:$pass",
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_HTTPHEADER => [
        "Content-Type: application/json",
        "Accept: application/json"
    ]
]);

$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);

curl_close($ch);

header('Content-Type: text/plain; charset=utf-8');
echo "HTTP CODE: $code\n\n";
if ($error) {
    echo "CURL ERROR: $error\n\n";
}
echo $response;