'Windows 10 (1507)', 'Microsoft Windows NT 10.0.10586.0' => 'Windows 10 (1511)', 'Microsoft Windows NT 10.0.14393.0' => 'Windows 10 (1607)', 'Microsoft Windows NT 10.0.15063.0' => 'Windows 10 (1703)', 'Microsoft Windows NT 10.0.16299.0' => 'Windows 10 (1709)', 'Microsoft Windows NT 10.0.17134.0' => 'Windows 10 (1803)', 'Microsoft Windows NT 10.0.17763.0' => 'Windows 10 (1809)', 'Microsoft Windows NT 10.0.18362.0' => 'Windows 10 (1903)', 'Microsoft Windows NT 10.0.18363.0' => 'Windows 10 (1909)', 'Microsoft Windows NT 10.0.19041.0' => 'Windows 10 (2004)', 'Microsoft Windows NT 10.0.19042.0' => 'Windows 10 (20H2)', 'Microsoft Windows NT 10.0.19043.0' => 'Windows 10 (21H1)', 'Microsoft Windows NT 10.0.19044.0' => 'Windows 10 (21H2)', 'Microsoft Windows NT 10.0.19045.0' => 'Windows 10 (22H2)', 'Microsoft Windows NT 10.0.22000.0' => 'Windows 11 (21H2)', 'Microsoft Windows NT 10.0.22621.0' => 'Windows 11 (22H2)', 'Microsoft Windows NT 10.0.22631.0' => 'Windows 11 (23H2)', 'Microsoft Windows NT 10.0.26100.0' => 'Windows 11 (24H2)', 'Microsoft Windows NT 10.0.26200.0' => 'Windows 11 (25H2)', ]; $DEVICES ??= []; if ($_SERVER['PATH_INFO'] === '/log') { header("Content-Type: text/html; charset=UTF-8"); echo "Table - Activity Statistics - Elwig\n"; echo "\n"; if ($_SERVER['QUERY_STRING'] === 'full') { passthru(<<:g' EOF); } else { passthru(<<:g' EOF); } echo "
TimestampIP AddressMethodURIFormatUser Agent
:g;s:^:
:g;s:$:
:g;s:^:
:g;s:$:
\n"; exit; } else if ($_SERVER['PATH_INFO'] === '') { $format = get_fmt(); $stat = []; if (($file = fopen('.log.csv', 'r'))) { while (($line = fgets($file)) !== false) { $line = explode('|', $line); if (sizeof($line) < 6) continue; if (!str_starts_with($line[5], 'Elwig/')) continue; if (str_contains($line[5], "PICARD") || str_contains($line[5], "ENTERPRISE") || str_contains($line[5], "GEORGIOU")) continue; $timestamp = intval($line[0]); $version = substr(explode(' ', $line[5], 2)[0], 6); $comment = preg_match("/\((.*?), *(.*?), *(.*?), *(.*?)\)/", $line[5], $m); $token = $m[1]; $branch = $m[2]; $device = $m[3]; $win = $m[4]; if (!isset($stat[$token])) $stat[$token] = []; if (!isset($stat[$token][$device])) $stat[$token][$device] = []; $addr = $line[1]; if (str_contains($addr, ':')) { $list = explode(':', $addr); $addr = implode(':', array_splice($list, 0, 4)) . '::'; } $stat[$token][$device][$timestamp] = [$version, $branch, $win, $addr]; } fclose($file); } if ($format === 'json') { header('Content-Type: application/json; charset=UTF-8'); echo "{\"clients\":[\n"; $first1 = true; foreach ($stat as $token => $devices) { if (!$first1) echo ",\n"; echo " {\"token\": \"$token\", \"devices\": [\n"; $first2 = true; foreach ($devices as $device => $data) { if (!$first2) echo ",\n"; echo " {"; $timestamp = array_key_last($data); $ref = $timestamp; foreach (array_reverse(array_keys($data)) as $t) { if ($t + 90 * 60 > $ref) { $ref = $t; } else { break; } } $addr = array_reverse(array_unique(array_map(function ($d) { return "\"$d[3]\""; }, array_values($data)))); $d = $data[$timestamp]; $name = $DEVICES[$token][$device] ?? $device; $active = $timestamp + 90 * 60 > time(); $activeStr = $active ? 'true' : 'false'; $from = date('c', $ref); $to = date('c', $timestamp); $hours = intval((($active ? time() : $timestamp) - $ref) / 60 / 60 + 0.4); $win = isset($osVersions[$d[2]]) ? '"' . $osVersions[$d[2]] . '"' : "null"; echo "\"branch\": \"$d[1]\", \"description\": \"$name\", \"name\": \"$device\", \"isActive\": $activeStr, " . "\"lastActivity\": {\"start\": \"$from\", \"end\": \"$to\", \"hours\": $hours}, " . "\"elwigVersion\": \"$d[0]\", \"osVersion\": $win, \"osVersionFull\": \"$d[2]\", " . "\"addresses\": [" . implode(",", $addr) . "]"; echo "}"; $first2 = false; } echo "\n ]}"; $first1 = false; } echo "\n]}\n"; } else if ($format === 'text') { header('Content-Type: text/plain; charset=UTF-8'); echo "Client Branch Device Device Name Last Activity Elwig Version OS Version IP Addresses\n"; foreach ($stat as $token => $devices) { foreach ($devices as $device => $data) { echo "$token "; $timestamp = array_key_last($data); $ref = $timestamp; foreach (array_reverse(array_keys($data)) as $t) { if ($t + 90 * 60 > $ref) { $ref = $t; } else { break; } } $addr = array_reverse(array_unique(array_map(function ($d) { return $d[3]; }, array_values($data)))); $d = $data[$timestamp]; $name = $DEVICES[$token][$device] ?? $device; echo mb_str_pad($d[1], 16) . " " . mb_str_pad($name, 20) . " " . mb_str_pad($device, 20) . " "; if ($timestamp + 90 * 60 > time()) { echo mb_str_pad(date('d.m.Y, H:i', $timestamp) . " (since " . intval((time() - $ref) / 60 / 60 + 0.4) . "h)", 28); } else { echo mb_str_pad(date('d.m.Y, H:i', $timestamp) . " (for " . intval(($timestamp - $ref) / 60 / 60 + 0.4) . "h)", 28); } echo " " . mb_str_pad($d[0], 13) . " "; if (isset($osVersions[$d[2]])) { echo mb_str_pad($osVersions[$d[2]], 33) . " "; } else { echo mb_str_pad($d[2], 33) . " "; } echo implode(", ", array_slice($addr, 0, 5)); echo "\n"; } } } else { header('Content-Type: text/html; charset=UTF-8'); echo "\n\n"; echo "Activity Statistics - Elwig\n"; echo "\n"; echo "

Activity Statistics

\n"; echo "\n"; echo "\n"; foreach ($stat as $token => $devices) { $first = true; foreach ($devices as $device => $data) { echo ""; if ($first) { $n = sizeof($devices); echo ""; $first = false; } $timestamp = array_key_last($data); $ref = $timestamp; foreach (array_reverse(array_keys($data)) as $t) { if ($t + 90 * 60 > $ref) { $ref = $t; } else { break; } } $addr = array_reverse(array_unique(array_map(function ($d) { return $d[3]; }, array_values($data)))); $d = $data[$timestamp]; $name = $DEVICES[$token][$device] ?? $device; echo ""; if ($timestamp + 90 * 60 > time()) { echo ""; echo ""; echo ""; } else { echo ""; echo ""; echo ""; } echo ""; if (isset($osVersions[$d[2]])) { echo ""; } else { echo ""; } echo ""; echo "\n"; } } echo "
ClientBranchDeviceDevice NameLast ActivityElwig VersionOS VersionIP Addresses
$token$d[1]$name$device" . date('d.m.Y, H:i', $timestamp) . " (since " . intval((time() - $ref) / 60 / 60 + 0.4) . "h)$name$device" . date('d.m.Y, H:i', $timestamp) . " (for " . intval(($timestamp - $ref) / 60 / 60 + 0.4) . "h)$d[0]" . $osVersions[$d[2]] . "$d[2]" . implode("
", array_slice($addr, 0, 5)) . "
\n"; echo "

Log Full Log

\n"; echo "\n\n"; } } else { header('Status: 404'); header('Content-Length: 0'); exit(); }