} } else { if (preg_match("/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\/\\d{1,2}?\$/", $ip_cidr)) { // Net without ID $total_host += Util::host_in_net($ip_cidr); $name = $target; $perm = TRUE; } else { if (preg_match("/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\$/", $ip_cidr)) { // Host without ID $total_host++; $name = $target; $perm = TRUE; if (count($sensors) == 0) { $closetnet_id = key(Asset_host::get_closest_net($conn, $ip_cidr)); $sensors = array_keys(Asset_net_sensors::get_sensors_by_id($conn, $closetnet_id)); } } else { if ($unresolved) { // the target is a hostname $total_host++; $perm = true; $name = '-'; if (count($sensors) == 0) { $sensors = $ids; } } } } } }
die; } $detail = "<img class='detail_img' src='" . AV_PIXMAPS_DIR . "/show_details.png'/>"; $results = array(); foreach ($nets as $_id => $net_data) { // Alarms $alarms = Asset_net::has_alarms($conn, $_id); $alarms_icon = $alarms ? "<img src='" . AV_PIXMAPS_DIR . "/assets_tick_gray.png'/>" : '-'; // Vulns $vulns = Asset_net::get_vulnerability_number($conn, $_id); $vulns_icon = $vulns > 0 ? "<img src='" . AV_PIXMAPS_DIR . "/assets_tick_gray.png'/>" : '-'; // Events $events = Asset_net::has_events($conn, $_id); $events_icon = $events ? "<img src='" . AV_PIXMAPS_DIR . "/assets_tick_gray.png'/>" : '-'; // Sensors $sensors = Asset_net_sensors::get_sensors_by_id($conn, $_id); $sensors_string = ''; foreach ($sensors as $sensor_id => $sensor_data) { if ($sensors_string != '') { $sensors_string .= ', '; } $sensors_string .= $sensor_data['name']; } // COLUMNS $_res = array(); $_res['DT_RowId'] = $_id; $_res[] = $net_data['name']; $_res[] = Util::utf8_encode2($net_data['owner']); $_res[] = Asset::format_to_print($net_data['ips']); $_res[] = $sensors_string; $_res[] = $alarms_icon;
function get_assets($conn, $id, $type, $host_types) { $filters = array('where' => 'sensor_properties.has_nagios = 1', 'order_by' => 'priority desc'); list($nagios_list, $nagios_total) = Av_sensor::get_list($conn, $filters); $sensor = NULL; $sensors = array(); $type = strtolower($type); $id = strtoupper($id); // in_assets first $in_assets = is_in_assets($conn, $id, $type); //Host, sensor or server if (in_array($type, $host_types)) { $table = $type; if ($type == 'host') { $what = 'host_id'; $table = 'host_ip'; } else { $what = 'id'; } $query = "SELECT INET6_NTOA(ip) AS ip FROM {$table} WHERE {$what} = UNHEX(?) LIMIT 1"; $params = array($id); $rs = $conn->Execute($query, $params); if ($rs) { $ips = $rs->fields['ip']; } // Related sensors if ($type == 'host') { $sensors = Asset_host_sensors::get_sensors_by_id($conn, $id); } elseif ($type == 'sensor') { $sensors[$id] = $ips; } else { $s_id = Av_sensor::get_id_by_ip($conn, Util::get_default_admin_ip()); $sensors[$s_id] = Util::get_default_admin_ip(); } } elseif ($type == 'net') { $query = "SELECT ips FROM net WHERE id = UNHEX(?)"; $params = array($id); $rs = $conn->Execute($query, $params); if ($rs) { $ips = $rs->fields['ips']; } // Related sensors $sensors = Asset_net_sensors::get_sensors_by_id($conn, $id); } elseif ($type == 'net_group' || $type == 'netgroup') { $query = "SELECT hex(ngr.net_id) as net_id, n.ips FROM net_group_reference AS ngr, net AS n\n WHERE ngr.net_group_id = UNHEX(?) AND ngr.net_id = n.id"; $net_ids = array($id); $params = $net_ids; $rs = $conn->Execute($query, $params); if ($rs) { $ipng = array(); if (!$rs->EOF) { $net_ids = array(); } while (!$rs->EOF) { $ipng[] = $rs->fields['ips']; $net_ids[] = $rs->fields['net_id']; $rs->MoveNext(); } $ips = count($ipng) > 0 ? implode(",", $ipng) : "'0.0.0.0/0'"; if (count($ipng) == 0) { $in_assets = 0; } } // Related sensors foreach ($net_ids as $net_id) { $_sensors_aux = Asset_net_sensors::get_sensors_by_id($conn, $net_id); foreach ($_sensors_aux as $sensor_id => $sensor_data) { $sensors[$sensor_id] = $sensor_data['ip']; } } } elseif ($type == 'host_group' || $type == 'hostgroup') { $query = "SELECT hex(hg.host_id) as host_id, INET6_NTOA(hi.ip) AS ip FROM host_group_reference hg, host_ip hi\n WHERE hi.host_id=hg.host_id AND hg.host_group_id = UNHEX(?)"; $host_ids = array($id); $params = $host_ids; $rs = $conn->Execute($query, $params); if ($rs) { $iphg = array(); if (!$rs->EOF) { $host_ids = array(); } while (!$rs->EOF) { $iphg[] = "'" . $rs->fields['ip'] . "'"; $host_ids[] = $rs->fields['host_id']; $rs->MoveNext(); } $ips = count($iphg) > 0 ? implode(',', $iphg) : "'0.0.0.0'"; if (count($iphg) == 0) { $in_assets = 0; } } // Related sensors foreach ($host_ids as $host_id) { $_sensors_aux = Asset_host_sensors::get_sensors_by_id($conn, $host_id); foreach ($_sensors_aux as $sensor_id => $sensor_data) { $sensors[$sensor_id] = $sensor_data['ip']; } } } //Getting first Nagios sensor (By priority) if ($nagios_total > 0) { foreach ($nagios_list as $n_sensor_id => $n_sensor_data) { if (array_key_exists($n_sensor_id, $sensors)) { $sensor = $n_sensor_data['ip']; break; } } } return array($id, $sensor, $type, $ips, $in_assets); }