= 400) return null; return json_decode($response, true); } function get_wazuh_token() { global $api_url, $api_user, $api_pass; if (!isset($_SESSION['wazuh_token'])) { $auth = call_wazuh_api("{$api_url}/security/user/authenticate", 'POST', null, "{$api_user}:{$api_pass}"); if ($auth && isset($auth['data']['token'])) { $_SESSION['wazuh_token'] = $auth['data']['token']; } else { return null; } } return $_SESSION['wazuh_token']; } function check_indexer_connection() { global $indexer_ip, $indexer_port, $indexer_user, $indexer_pass; $url = "https://{$indexer_ip}:{$indexer_port}/"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_TIMEOUT, 3); curl_setopt($ch, CURLOPT_USERPWD, "{$indexer_user}:{$indexer_pass}"); curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpcode == 200) return 'OK'; if ($httpcode == 401) return 'AUTH_FAILED'; return 'CONNECTION_ERROR'; } function get_custom_inventory_from_indexer($agent_id, $location) { global $indexer_ip, $indexer_port, $indexer_user, $indexer_pass; $url = "https://{$indexer_ip}:{$indexer_port}/wazuh-alerts-*/_search"; $payload = json_encode([ 'size' => 1, 'sort' => ['@timestamp' => 'desc'], 'query' => ['bool' => ['must' => [['match' => ['agent.id' => $agent_id]], ['match' => ['location' => $location]]]]] ]); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]); curl_setopt($ch, CURLOPT_USERPWD, "{$indexer_user}:{$indexer_pass}"); $response = curl_exec($ch); curl_close($ch); if ($response) { $data = json_decode($response, true); if (isset($data['hits']['hits'][0]['_source']['full_log'])) { $log = $data['hits']['hits'][0]['_source']['full_log']; $log = preg_replace('/^ossec: output: \'' . preg_quote($location, '/') . '\':\s*/', '', $log); // ป้องกัน json_decode พังถ้ารูปแบบผิด $json = json_decode($log, true); return $json !== null ? $json : $log; } } return null; } function get_indexer_metadata() { global $indexer_ip, $indexer_port, $indexer_user, $indexer_pass; $url = "https://{$indexer_ip}:{$indexer_port}/wazuh-alerts-*/_search"; $payload = json_encode([ 'size' => 10000, 'sort' => ['@timestamp' => 'desc'], 'query' => ['terms' => ['location' => ['teamviewer_inventory', 'anydesk_inventory', 'disk_inventory', 'model_inventory', 'manufacturer_inventory']]], '_source' => ['agent.id', 'location', 'full_log', 'agent.labels'] ]); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_TIMEOUT, 6); curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]); curl_setopt($ch, CURLOPT_USERPWD, "{$indexer_user}:{$indexer_pass}"); $response = curl_exec($ch); curl_close($ch); $metadata = []; if ($response) { $data = json_decode($response, true); if (isset($data['hits']['hits'])) { foreach ($data['hits']['hits'] as $hit) { $src = $hit['_source']; $aid = $src['agent']['id'] ?? ''; $loc = $src['location'] ?? ''; $log = $src['full_log'] ?? ''; $labels = $src['agent']['labels'] ?? null; if (!$aid) continue; if (!isset($metadata[$aid])) { $metadata[$aid] = ['tv' => null, 'ad' => null, 'asset_id' => null, 'location' => null, 'disk_c_total' => null, 'disk_c_free' => null, 'model' => null, 'manufacturer' => null]; } if ($labels) { if ($metadata[$aid]['asset_id'] === null && isset($labels['asset_id'])) $metadata[$aid]['asset_id'] = $labels['asset_id']; if ($metadata[$aid]['location'] === null && isset($labels['location'])) $metadata[$aid]['location'] = $labels['location']; } if ($loc === 'teamviewer_inventory' && $metadata[$aid]['tv'] === null) { $log = preg_replace('/^ossec: output: \'teamviewer_inventory\':\s*/', '', $log); $json = json_decode($log, true); $metadata[$aid]['tv'] = ($json && isset($json['TeamViewerID']) && $json['TeamViewerID'] !== 'Not Found') ? $json['TeamViewerID'] : 'None'; } if ($loc === 'anydesk_inventory' && $metadata[$aid]['ad'] === null) { $log = preg_replace('/^ossec: output: \'anydesk_inventory\':\s*/', '', $log); $json = json_decode($log, true); $metadata[$aid]['ad'] = ($json && isset($json['AnyDeskID']) && $json['AnyDeskID'] !== 'Not Found') ? $json['AnyDeskID'] : 'None'; } // 🌟 อัปเดตตัวกรอง Disk C สำหรับฝั่ง PHP (ดึงเข้า Excel) 🌟 if ($loc === 'disk_inventory' && $metadata[$aid]['disk_c_total'] === null) { $log = preg_replace('/^ossec: output: \'disk_inventory\':\s*/', '', $log); $json = json_decode($log, true); if ($json && !is_array($json) && is_object((object)$json)) { $json = [$json]; } if (is_array($json)) { foreach ($json as $disk) { // รองรับทั้งคีย์ DriveLetter, Drive, DeviceID, Name $dLetter = $disk['DriveLetter'] ?? $disk['Drive'] ?? $disk['DeviceID'] ?? $disk['Name'] ?? ''; // เช็คให้มีตัวอักษร C ไม่ว่าจะมาแบบ "C:", "C:\", "C" if (strpos(strtoupper($dLetter), 'C') !== false) { // รองรับขนาดทั้งหน่วย GB และ Bytes $t = $disk['Total_GB'] ?? $disk['SizeGB'] ?? (isset($disk['Size']) ? round($disk['Size'] / 1073741824, 2) : 0); $f = $disk['Free_GB'] ?? $disk['FreeGB'] ?? (isset($disk['FreeSpace']) ? round($disk['FreeSpace'] / 1073741824, 2) : 0); $metadata[$aid]['disk_c_total'] = $t ?: 'N/A'; $metadata[$aid]['disk_c_free'] = $f ?: 'N/A'; break; } } } } if ($loc === 'model_inventory' && $metadata[$aid]['model'] === null) { $log = preg_replace('/^ossec: output: \'model_inventory\':\s*/', '', $log); $json = json_decode($log, true); $metadata[$aid]['model'] = ($json && isset($json['PCModel'])) ? $json['PCModel'] : 'Unknown'; } if ($loc === 'manufacturer_inventory' && $metadata[$aid]['manufacturer'] === null) { $log = preg_replace('/^ossec: output: \'manufacturer_inventory\':\s*/', '', $log); $json = json_decode($log, true); $metadata[$aid]['manufacturer'] = ($json && isset($json['PCManufacturer'])) ? $json['PCManufacturer'] : 'Unknown'; } } } } return $metadata; } function format_os_name($agent) { if (($agent['id'] ?? '') === '000') return 'Wazuh Server'; $os_name = $agent['os']['name'] ?? $agent['os']['platform'] ?? 'Unknown'; $nameLower = strtolower($os_name); $version = $agent['os']['version'] ?? ''; if (strpos($nameLower, 'windows 11') !== false) return 'Windows 11'; if (strpos($nameLower, 'windows 10') !== false) return 'Windows 10'; if (strpos($nameLower, 'windows 7') !== false) return 'Windows 7'; if (strpos($nameLower, 'windows 8') !== false) return 'Windows 8'; if (strpos($nameLower, 'windows server 2022') !== false) return 'Windows Server 2022'; if (strpos($nameLower, 'windows server 2019') !== false) return 'Windows Server 2019'; if (strpos($nameLower, 'windows server 2016') !== false) return 'Windows Server 2016'; if (strpos($nameLower, 'windows server 2012') !== false) return 'Windows Server 2012'; if (strpos($nameLower, 'ubuntu') !== false) { if (preg_match('/Ubuntu (\d+\.\d+)/i', $os_name, $m)) return 'Ubuntu ' . $m[1]; return 'Ubuntu'; } if (strpos($nameLower, 'centos') !== false) { if (preg_match('/CentOS.*?(\d+)/i', $os_name, $m)) return 'CentOS ' . $m[1]; return 'CentOS'; } if (strpos($nameLower, 'mac') !== false || strpos($nameLower, 'darwin') !== false) { return $version ? 'macOS ' . $version : 'macOS'; } return $os_name; } // ========================================== // 3. ระบบ AJAX สำหรับดึงข้อมูล // ========================================== if (isset($_GET['action']) && $_GET['action'] === 'get_specs' && isset($_GET['agent_id'])) { header('Content-Type: application/json'); $token = get_wazuh_token(); if (!$token) { echo json_encode(['error' => 'Unauthorized']); exit; } $agent_id = htmlspecialchars($_GET['agent_id']); $hw_res = call_wazuh_api("{$api_url}/syscollector/{$agent_id}/hardware", 'GET', $token); $netiface_res = call_wazuh_api("{$api_url}/syscollector/{$agent_id}/netiface", 'GET', $token); $netaddr_res = call_wazuh_api("{$api_url}/syscollector/{$agent_id}/netaddr", 'GET', $token); $netproto_res = call_wazuh_api("{$api_url}/syscollector/{$agent_id}/netproto", 'GET', $token); $packages_res = call_wazuh_api("{$api_url}/syscollector/{$agent_id}/packages?limit=2000", 'GET', $token); $hotfixes_res = call_wazuh_api("{$api_url}/syscollector/{$agent_id}/hotfixes?limit=1000", 'GET', $token); $disk_info = get_custom_inventory_from_indexer($agent_id, 'disk_inventory'); $tv_info = get_custom_inventory_from_indexer($agent_id, 'teamviewer_inventory'); $anydesk_info = get_custom_inventory_from_indexer($agent_id, 'anydesk_inventory'); echo json_encode([ 'hardware' => $hw_res['data']['affected_items'][0] ?? null, 'disk_info' => $disk_info, 'tv_info' => $tv_info, 'anydesk_info' => $anydesk_info, 'netiface' => $netiface_res['data']['affected_items'] ?? [], 'netaddr' => $netaddr_res['data']['affected_items'] ?? [], 'netproto' => $netproto_res['data']['affected_items'] ?? [], 'packages' => $packages_res['data']['affected_items'] ?? [], 'hotfixes' => $hotfixes_res['data']['affected_items'] ?? [] ]); exit; } if (isset($_GET['action']) && $_GET['action'] === 'get_dashboard_data' && isset($_GET['agent_id'])) { header('Content-Type: application/json'); $token = get_wazuh_token(); $agent_id = htmlspecialchars($_GET['agent_id']); $hw_res = call_wazuh_api("{$api_url}/syscollector/{$agent_id}/hardware", 'GET', $token); $packages_res = call_wazuh_api("{$api_url}/syscollector/{$agent_id}/packages?limit=5000", 'GET', $token); $hotfixes_res = call_wazuh_api("{$api_url}/syscollector/{$agent_id}/hotfixes?limit=2000", 'GET', $token); echo json_encode(['hardware' => $hw_res['data']['affected_items'][0] ?? null, 'packages' => $packages_res['data']['affected_items'] ?? [], 'hotfixes' => $hotfixes_res['data']['affected_items'] ?? []]); exit; } if (isset($_GET['action']) && $_GET['action'] === 'get_processes' && isset($_GET['agent_id'])) { header('Content-Type: application/json'); $token = get_wazuh_token(); $agent_id = htmlspecialchars($_GET['agent_id']); $processes_res = call_wazuh_api("{$api_url}/syscollector/{$agent_id}/processes?limit=5000", 'GET', $token); echo json_encode(['processes' => $processes_res['data']['affected_items'] ?? []]); exit; } // ========================================== // 4. ดึงข้อมูลหน้าหลัก // ========================================== $token = get_wazuh_token(); $indexer_status = check_indexer_connection(); $agents = []; $all_metadata = []; $unique_os_list = []; if ($token) { $agents_response = call_wazuh_api("{$api_url}/agents?limit=10000", 'GET', $token); if ($agents_response && isset($agents_response['data']['affected_items'])) { $agents = $agents_response['data']['affected_items']; foreach ($agents as $agent) { $formatted_os = format_os_name($agent); $unique_os_list[$formatted_os] = true; } $unique_os_list = array_keys($unique_os_list); sort($unique_os_list); } if ($indexer_status === 'OK') { $all_metadata = get_indexer_metadata(); foreach ($agents as &$ag) { $aid = $ag['id']; if (isset($all_metadata[$aid])) { if (!isset($ag['labels'])) $ag['labels'] = []; if (isset($all_metadata[$aid]['asset_id'])) $ag['labels']['asset_id'] = $all_metadata[$aid]['asset_id']; if (isset($all_metadata[$aid]['location'])) $ag['labels']['location'] = $all_metadata[$aid]['location']; } } unset($ag); } } ?> Enterprise Asset Management

Enterprise Asset Management

Total Assets: Refresh
Wazuh API Error: ไม่สามารถยืนยันตัวตนได้ กรุณาตรวจสอบ IP หรือ Credentials
Wazuh Indexer Warning:
รหัสผ่าน Indexer ผิดพลาด ระบบจะไม่สามารถแสดงข้อมูล Custom Logs (เช่น PC Model, Remote ID)
Wazuh Indexer Disconnected:
ไม่สามารถเชื่อมต่อ Indexer พอร์ต 9200 ได้
Connected to API successfully, but no agents found.
Operating Systems
Hardware Models
RAM Distribution

REQUIRES SCAN

GLOBAL DEEP SCAN

Run a comprehensive scan to fetch Live RAM, Software, and Updates across all endpoints.

OS Endpoint & Asset Info IP Address Version Status Remote Actions
"; if ($ad_id) echo ""; } else { echo "-"; } ?>