if (!$all || Acl::cidrs_allowed($cidrs, $entityPerms["assets"])) { $result[] = $net->get_ips(); } } $all = count($entityPerms["sensors"]); $sensors = Sensor::get_all($conn); foreach ($sensors as $sensor) { if (!$all || $entityPerms["sensors"][$sensor->get_ip()]) { $result[] = $sensor->get_ip(); } } echo implode("\n", $result); $buffer = implode("\n", $result); } else { if ($key == "hostgroup") { $hg_list = Host_group::get_list($conn, "", "ORDER BY name"); if (count($hg_list) > 0) { $j = 0; $buffer .= "["; foreach ($hg_list as $hg) { if ($j >= $from && $j < $to) { $hg_name = $hg->get_name(); $hg_title = Util::htmlentities($hg_name); $hg_key = "hostgroup_" . base64_encode($hg_name); $hg_url = "NODES:" . $hg_title; $title = strlen($hg_name) > $length_name ? substr($hg_name, 0, $length_name) . "..." : $hg_name; $title = Util::htmlentities($title); $tooltip = $hg_title; $li = "key:'{$hg_key}', isLazy:true , url:'{$hg_url}', icon:'../../pixmaps/theme/host_group.png', title:'{$title}', tooltip:'{$tooltip}'\n"; $buffer .= ($j > $from ? "," : "") . "{ {$li} }\n"; }
function getHostGroupList() { global $conn; if ($host_list = Host_group::get_list($conn, '', '')) { return $host_list; } return ''; }
function draw_members_select($form_data) { global $conn, $id; $resp = new xajaxResponse(); $type = $form_data['member_type']; // The user selected the empty type if (!$type) { $resp->AddAssign("members_select", "innerHTML", _("Please select a type")); return $resp; } // // Get the list of members of the given type // $options = array(); switch ($type) { case 'host': include_once 'classes/Host.inc'; $list = Host::get_list($conn, "", 'ORDER BY hostname'); print_r($list); foreach ($list as $obj) { $descr = $obj->get_descr(); if (strlen($descr) > 50) { $descr = substr($descr, 0, 47) . '...'; } $options[$obj->get_ip()] = $obj->get_hostname() . ' ' . $obj->get_ip() . ' - ' . $descr; } break; case 'net': include_once 'classes/Net.inc'; $list = Net::get_list($conn, "", 'ORDER BY name'); foreach ($list as $obj) { $descr = $obj->get_descr(); if (strlen($descr) > 50) { $descr = substr($descr, 0, 47) . '...'; } $options[$obj->get_name()] = $obj->get_name() . ' ' . $obj->get_ips() . ' - ' . $descr; } break; case 'host_group': include_once 'classes/Host_group.inc'; $list = Host_group::get_list($conn, "", 'ORDER BY name'); foreach ($list as $obj) { $descr = $obj->get_descr(); if (strlen($descr) > 50) { $descr = substr($descr, 0, 47) . '...'; } $options[$obj->get_name()] = $obj->get_name() . ' - ' . $descr; } break; case 'net_group': include_once 'classes/Net_group.inc'; $list = Net_group::get_list($conn, '', 'ORDER BY name'); foreach ($list as $obj) { $descr = $obj->get_descr(); if (strlen($descr) > 50) { $descr = substr($descr, 0, 47) . '...'; } $options[$obj->get_name()] = $obj->get_name() . ' - ' . $descr; } break; } // // Build the SELECT tag // $html = '<select name="member_name">'; foreach ($options as $name => $description) { $html .= "<option value='{$name}'>{$description}</option>"; } $html .= '</select>'; $resp->AddAssign("members_select", "innerHTML", $html); return $resp; }
$total_hosts++; } } } } if ($key == "hostgroup") { if ($filter == "") { $wherehg = ""; } else { if (preg_match("/\\d+.\\d+/", $filter)) { $wherehg = " AND r.host_ip like '%{$filter}%'"; } else { $wherehg = " AND g.name like '%{$filter}%'"; } } $hg_list = Host_group::get_list($conn, $wherehg); if (count($hg_list) > 0) { $j = 0; $buffer .= "["; foreach ($hg_list as $hg) { if ($j >= $from && $j < $to) { $hg_name = $hg->get_name(); $hg_title = utf8_encode($hg_name); $hg_url = "HOST_GROUP:" . $hg_title; $hg_key = "hostgroup_" . base64_encode($hg_name); $title = strlen($hg_name) > $length_name ? substr($hg_name, 0, $length_name) . "..." : $hg_name; $title = Util::htmlentities(utf8_encode($title)); $tooltip = Util::htmlentities($hg_title); $li = "key:'{$hg_key}', isLazy:true , url:'{$hg_url}', icon:'../../pixmaps/theme/host_group.png', title:'{$title}', tooltip:'{$tooltip}'\n"; $buffer .= ($j > $from ? "," : "") . "{ {$li} }\n"; }
function update_db($global_info, $scan) { $db = new ossim_db(); $conn = $db->connect(); $array_os = array("win" => "1", "linux" => "2", "cisco" => "3", "freebsd" => "5", "netbsd" => "6", "openbsd" => "7", "hp-ux" => "8", "solaris" => "9", "macos" => "10", "plan9" => "11", "sco" => "12", "aix" => "13", "unix" => "14"); $ips = $global_info["ips"]; $sensors = $global_info["sboxs"]; $nagios = $global_info['nagios']; // load protocol ids $protocol_ids = array(); if ($protocol_list = Protocol::get_list($conn)) { foreach ($protocol_list as $protocol_data) { $protocol_ids[$protocol_data->get_name()] = $protocol_data->get_id(); } } for ($i = 0; $i < $ips; $i++) { $ip = $global_info["ip_{$i}"]; if (!empty($ip)) { $hosts[] = $ip; //gethostbyaddr($ip); $os = $scan[$ip]["os"]; $os_id = 0; foreach ($array_os as $k => $v) { if (preg_match("/{$k}/i", $os)) { $os_id = $v; break; } } if (Host::in_host($conn, $ip)) { echo "* " . gettext("Updating") . " {$ip}..<br/>"; Host::update($conn, $ip, gethostbyaddr($ip), $global_info["asset"], $global_info["threshold_c"], $global_info["threshold_a"], $global_info["rrd_profile"], 0, 0, $global_info["nat"], $sensors, $global_info["descr"], $scan["{$ip}"]["os"], $scan["{$ip}"]["mac"], $scan["{$ip}"]["mac_vendor"]); Host_scan::delete($conn, $ip, 3001); //if (isset($global_info["nessus"])) { Host_scan::insert($conn, $ip, 3001, 0); } } else { echo "<span style='color='blue'>\n"; echo "* " . gettext("Inserting") . " {$ip}..<br/>\n"; echo "</span>\n"; Host::insert($conn, $ip, gethostbyaddr($ip), $global_info["asset"], $global_info["threshold_c"], $global_info["threshold_a"], $global_info["rrd_profile"], 0, 0, $global_info["nat"], $sensors, $global_info["descr"], $scan[$ip]["os"], $scan[$ip]["mac"], $scan[$ip]["mac_vendor"]); // if (isset($global_info["nessus"])) { Host_scan::insert($conn, $ip, 3001, 0); } } if ($os_id != 0) { Host_plugin_sid::delete($conn, $ip, 5001); Host_plugin_sid::insert($conn, $ip, 5001, $os_id); } if (!empty($nagios)) { if (!Host_scan::in_host_scan($conn, $ip, 2007)) { Host_scan::insert($conn, $ip, 2007, "", $ip, $sensors, ""); } } else { if (Host_scan::in_host_scan($conn, $ip, 2007)) { Host_scan::delete($conn, $ip, 2007); } } /* Services */ Host_plugin_sid::delete($conn, $ip, 5002); foreach ($scan[$ip]["services"] as $port_proto => $service) { $service["proto"] = $protocol_ids[strtolower(trim($service["proto"]))]; Host_services::insert($conn, $ip, $service["port"], strftime("%Y-%m-%d %H:%M:%S"), $_SERVER["SERVER_ADDR"], $service["proto"], $service["service"], $service["service"], $service["version"], 1); Host_plugin_sid::insert($conn, $ip, 5002, $service["port"]); } flush(); } } // Insert group name $groupname = $global_info["groupname"]; if (!empty($groupname) && !empty($hosts)) { $exists_hosts = count(Host_group::get_list($conn, " AND g.name='{$groupname}'")) > 0; if ($exists_hosts) { echo "<br/>" . _("The group name already exists") . "<br/>"; } else { Host_group::insert($conn, $groupname, $global_info["threshold_c"], $global_info["threshold_a"], $global_info["rrd_profile"], $sensors, $hosts, $global_info["descr"]); } //if (isset($global_info["nessus"])) { Host_group_scan::insert($conn, $groupname, 3001, 0); } if (!empty($nagios)) { Host_group_scan::insert($conn, $groupname, 2007, 0); } } $db->close($conn); }
require_once "classes/Scan.inc"; require_once "classes/Sensor.inc"; Session::logcheck("MenuPolicy", "ToolsScan"); $db = new ossim_db(); $conn = $db->connect(); $net_group_list = Net_group::get_list($conn); $net_list = Net::get_list($conn); $assets = array(); foreach ($net_list as $_net) { $assets_aux[] = '{ txt:"NET:' . $_net->get_name() . ' [' . $_net->get_ips() . ']", id: "' . $_net->get_ips() . '" }'; } $host_list = Host::get_list($conn); foreach ($host_list as $_host) { $assets_aux[] = '{ txt:"HOST:' . $_host->get_ip() . ' [' . $_host->get_hostname() . ']", id: "' . $_host->get_ip() . '/32" }'; } $host_group_list = Host_group::get_list($conn); foreach ($host_group_list as $_host_group) { $hosts = $_host_group->get_hosts($conn, $_host_group->get_name()); $ids = null; foreach ($hosts as $k => $v) { $ids .= $v->get_host_ip() . "/32 "; } $assets_aux[] = '{ txt:"HOSTGROUP:' . $_host_group->get_name() . '", id: "' . rtrim($ids) . '" }'; } $sensor_list = Sensor::get_list($conn, "ORDER BY name"); foreach ($sensor_list as $_sensor) { $assets_aux[] = '{ txt:"SENSOR:' . $_sensor->get_name() . ' [' . $_sensor->get_ip() . ']", id: "' . $_sensor->get_ip() . '/32" }'; } $assets = implode(",\n", $assets_aux); $db->close($conn); require_once "ossim_conf.inc";
$threshold_a = $_SESSION['_hostgroup']['threshold_a']; $threshold_c = $_SESSION['_hostgroup']['threshold_c']; $rrd_profile = $_SESSION['_hostgroup']['rrd_profile']; $nagios = $_SESSION['_hostgroup']['nagios']; unset($_SESSION['_hostgroup']); } else { $conf = $GLOBALS["CONF"]; $threshold_a = $threshold_c = $conf->get_conf("threshold"); $descr = $nagios = ""; $hosts = $sensors = array(); if ($hgname != '') { ossim_valid($hgname, OSS_ALPHA, OSS_SPACE, OSS_PUNC, OSS_NULLABLE, OSS_SQL, 'illegal:' . _("Host Group Name")); if (ossim_error()) { die(ossim_error()); } if ($host_group_list = Host_group::get_list($conn, " AND g.name = '{$hgname}'")) { $host_group = $host_group_list[0]; $descr = $host_group->get_descr(); $threshold_c = $host_group->get_threshold_c(); $threshold_a = $host_group->get_threshold_a(); $obj_hosts = $host_group->get_hosts($conn); foreach ($obj_hosts as $host) { $hosts[] = $host->get_host_ip($conn); } $nagios = Host_group_scan::in_host_group_scan($conn, $hgname, 2007) ? "1" : ''; $rrd_profile = $host_group->get_rrd_profile(); if (!$rrd_profile) { $rrd_profile = "None"; } $tmp_sensors = $host_group->get_sensors($conn); foreach ($tmp_sensors as $sensor) {
} if (empty($order)) { $order = "name"; } $start = ($page - 1) * $rp; $limit = "LIMIT {$start}, {$rp}"; $xml = ""; $where = ""; if ($field == "name") { $where = " AND g.name like '%{$search}%'"; } else { if ($field == "ip") { $where = " AND r.host_ip like '%{$search}%'"; } } $host_group_list = Host_group::get_list($conn, $where, "ORDER BY {$order} {$limit}"); if ($host_group_list[0]) { $total = $host_group_list[0]->get_foundrows(); if ($total == 0) { $total = count($host_group_list); } } else { $total = 0; } $xml .= "<rows>\n"; $xml .= "<page>{$page}</page>\n"; $xml .= "<total>{$total}</total>\n"; foreach ($host_group_list as $host_group) { $name = $host_group->get_name(); $xml .= "<row id='" . htmlspecialchars(utf8_encode($name)) . "'>"; $link_modify = "<a style='font-weight:bold;' href=\"./newhostgroupform.php?name=" . urlencode($name) . "\">" . utf8_encode(Util::htmlentities($name)) . "</a>";