if ($j > $to) { $li = "key:'hostgroup', page:'{$nextpage}', isFolder:true, isLazy:true, icon:'../../pixmaps/theme/host_group.png', title:'" . _("next") . " {$maxresults} " . _("host group") . "'"; $buffer .= ",{ {$li} }\n"; } $buffer .= "]"; } if ($buffer == "" || $buffer == "[]") { echo "[{title:'" . _("No Host groups Found") . "', noLink:true}]"; } else { echo $buffer; } } else { if (preg_match("/hostgroup_(.*)/", $key, $found)) { $length_hn = $length_name + 5; $buffer .= "["; if ($hg_hosts = Host_group::get_hosts($conn, base64_decode($found[1]))) { $k = 1; $j = 0; $html = ""; foreach ($hg_hosts as $hosts) { if ($j >= $from && $j < $to) { $ip = $hosts->get_host_ip(); if (isset($ossim_hosts[$ip])) { // Test filter $hname = $ip == $ossim_hosts[$ip] ? "" : $ossim_hosts[$ip]; $host_key = utf8_encode($key . $k); $aux_hname = strlen($hname) > $length_hn ? substr($hname, 0, $length_hn) . "..." : $hname; $title = $hname == '' ? $ip : "{$ip} <font style=\"font-size:80%\">(" . Util::htmlentities($aux_hname) . ")</font>"; $tooltip = $hname == '' ? $ip : $ip . " (" . $hname . ")"; $html .= "{ key:'{$host_key}', url:'{$ip}', icon:'../../pixmaps/theme/host.png', title:'{$title}', tooltip:'{$tooltip}' },\n"; $k++;
} $j++; } } if ($i > $to) { $html .= "{ key:'{$key}', page:'{$nextpage}', isFolder:true, isLazy:true, icon:'../../pixmaps/theme/host_group.png', title:'" . _("next") . " {$maxresults} " . _("hosts") . "' },"; } if ($html != "") { $buffer .= preg_replace("/,\$/", "", $html); } $buffer .= "]"; if ($buffer == "[]") { $buffer = "[{title:'" . _("No Hosts Found") . "', noLink:true}]"; } } elseif ($key == "host_group") { $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(utf8_encode($hg_name)); $hg_key = utf8_encode("HOSTGROUP:" . $hg_name); $asset_data = array(); foreach ($hg->get_hosts($conn, $hg_name) as $k => $v) { $asset_data[] = $v->get_host_ip() . "/32"; } $title = strlen($hg_name) > $length_name ? substr($hg_name, 0, $length_name) . "..." : $hg_name; $title = Util::htmlentities(utf8_encode($title)); $tooltip = $hg_title;
} } if ($nagios) { if (Host_group_scan::in_host_group_scan($conn, $hgname, 2007)) { Host_group_scan::delete($conn, $hgname, 2007); } Host_group_scan::insert($conn, $hgname, 2007); $q = new NagiosAdm(); $q->addNagiosHostGroup(new NagiosHostGroup($hgname, $hosts, $sensors), $conn); $q->close(); } else { if (Host_group_scan::in_host_group_scan($conn, $hgname, 2007)) { Host_group_scan::delete($conn, $hgname, 2007); } } Host_group::update($conn, $hgname, $threshold_c, $threshold_a, $rrd_profile, $sensors, $hosts, $descr); $db->close($conn); Util::clean_json_cache_files("(policy|vulnmeter|hostgroup)"); } if (isset($_SESSION['_hostgroup'])) { unset($_SESSION['_hostgroup']); } if ($_SESSION["menu_sopc"] == "Host groups" && POST('withoutmenu') != "1") { ?> <p><?php echo gettext("Host group succesfully updated"); ?> </p> <script type='text/javascript'>document.location.href="hostgroup.php"</script> <?php } else {
function get_values($conn, $host_types, $type, $name) { // r --> bad // a --> medium // v --> good $RiskValue = 'b'; $VulnValue = 'b'; $AvailValue = 'b'; if (in_array($type, $host_types)) { if ($type == "host") { $what = "hostname"; } $query = "select ip from {$type} where {$what} = ?"; $params = array($name); if ($rs3 =& $conn->Execute($query, $params)) { $name = $rs3->fields["ip"]; if ($rs3->EOF) { $in_assets = 0; } } // related sensor $sensor = $name; if ($type == "host") { require_once 'classes/Host.inc'; $sensors = Host::get_related_sensors($conn, $name); $sensor = $sensors[0] != "" ? $sensors[0] : $name; } } elseif ($type == "net") { $query = "select ips from net where name = ?"; $params = array($name); if ($rs3 =& $conn->Execute($query, $params)) { $ips = $rs3->fields["ips"]; if ($rs3->EOF) { $in_assets = 0; } } // related sensor require_once 'classes/Net.inc'; $sensors = Net::get_related_sensors($conn, $name); $sensor = $sensors[0] != "" ? $sensors[0] : $name; } elseif ($type == "host_group") { $query = "select host_ip from host_group_reference where host_group_name = ?"; $params = array($name); if ($rs3 =& $conn->Execute($query, $params)) { $iphg = array(); while (!$rs3->EOF) { $iphg[] = "'" . $rs3->fields["host_ip"] . "'"; $rs3->MoveNext(); } $ips = count($iphg) > 0 ? implode(",", $iphg) : "'0.0.0.0'"; if (count($iphg) == 0) { $in_assets = 0; } } // related sensor{ require_once 'classes/Host_group.inc'; $sensors = Host_group::get_related_sensors($conn, $name); $sensor = $sensors[0] != "" ? $sensors[0] : $name; } $params = $type == "host_group" ? array() : array($name); if (in_array($type, $host_types)) { $query = "select severity,member from bp_member_status where member = ? and measure_type = \"host_metric\""; } elseif ($type == "host_group") { $query = "select severity,member from bp_member_status where member in ({$ips}) and measure_type = \"host_metric\" order by severity desc limit 1"; } else { $query = "select severity,member from bp_member_status where member = ? and measure_type = \"net_metric\""; } if (!($rs2 =& $conn->Execute($query, $params))) { print $conn->ErrorMsg(); } else { $r_ip = $rs2->fields["member"]; if (intval($rs2->fields["severity"]) > 7) { $RiskValue = 'r'; } elseif (intval($rs2->fields["severity"]) > 3) { $RiskValue = 'a'; } elseif ($rs2->fields["severity"] != "") { $RiskValue = 'v'; } } if (in_array($type, $host_types)) { $query = "select severity,member from bp_member_status where member = ? and measure_type = \"host_vulnerability\""; } elseif ($type == "host_group") { $query = "select severity,member from bp_member_status where member in ({$ips}) and measure_type = \"host_vulnerability\" order by severity desc limit 1"; } else { $query = "select severity,member from bp_member_status where member = ? and measure_type = \"net_vulnerability\""; } if (!($rs2 =& $conn->Execute($query, $params))) { print $conn->ErrorMsg(); } else { $v_ip = $rs2->fields["member"]; if (intval($rs2->fields["severity"]) > 7) { $VulnValue = 'r'; } elseif (intval($rs2->fields["severity"]) > 3) { $VulnValue = 'a'; } elseif ($rs2->fields["severity"] != "") { $VulnValue = 'v'; } } if (in_array($type, $host_types)) { $query = "select severity,member from bp_member_status where member = ? and measure_type = \"host_availability\""; } elseif ($type == "host_group") { $query = "select severity,member from bp_member_status where member in ({$ips}) and measure_type = \"host_availability\" order by severity desc limit 1"; } else { $query = "select severity,member from bp_member_status where member = ? and measure_type = \"net_availability\""; } if (!($rs2 =& $conn->Execute($query, $params))) { print $conn->ErrorMsg(); } else { $a_ip = $rs2->fields["member"]; if (intval($rs2->fields["severity"]) > 7) { $AvailValue = 'r'; } elseif (intval($rs2->fields["severity"]) > 3) { $AvailValue = 'a'; } elseif ($rs2->fields["severity"] != "") { $AvailValue = 'v'; } } return array($RiskValue, $VulnValue, $AvailValue, $sensor, $r_ip, $v_ip); }
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; }
function getHostGroupList() { global $conn; if ($host_list = Host_group::get_list($conn, '', '')) { return $host_list; } return ''; }
function show_form() { global $sensor_list; global $net_group_list; global $host_group_list; global $hosts_list; global $nets_list; global $conn; global $sensor_index; global $net_group_index; global $host_group_index; global $hosts_index; global $nets_index; $global_i = 0; $num = count($sensor_list); if ($num > 20) { $cols = 5; } else { $cols = 3; } $rows = intval($num / $cols) + 1; $num_ng = count($net_group_list); if ($num_ng > 20) { $cols = 5; } else { $cols = 3; } $rows_ng = intval($num_ng / $cols) + 1; $num_hg = count($host_group_list); if ($num_hg > 20) { $cols = 5; } else { $cols = 3; } $rows_hg = intval($num_hg / $cols) + 1; $num_hs = count($hosts_list); if ($num_hs > 20) { $cols = 5; } else { $cols = 3; } $rows_hs = intval($num_hs / $cols) + 1; $num_ns = count($nets_list); if ($num_ns > 20) { $cols = 5; } else { $cols = 3; } $rows_ns = intval($num_ns / $cols) + 1; if ($num_ns + $num_hs + $num_hg + $num_ng > 20) { $cols_full = 5; } else { $cols_full = 3; } ?> <h3><center> <?php echo _("Select sensors for this scan"); ?> </center></h3> <ul> <?php $group_scan_list = Net_group_scan::get_list($conn, "WHERE plugin_id = " . NESSUS); foreach ($group_scan_list as $group_scan) { $net_group_sensors = Net_group::get_sensors($conn, $group_scan->get_net_group_name()); echo "\n<script>\n"; echo "var " . $group_scan->get_net_group_name() . " = true;\n"; echo "</script>\n"; $sensor_string = ""; foreach ($net_group_sensors as $ng_sensor => $name) { if ($sensor_string == "") { $sensor_string .= $sensor_index[$name]; } else { $sensor_string .= "," . $sensor_index[$name]; } } $nets_string = ""; $nets = Net_group::get_networks($conn, $group_scan->get_net_group_name(), NESSUS); foreach ($nets as $net) { $name = $net->get_net_name(); if ($nets_string == "") { $nets_string .= $nets_index[$name]; } else { $nets_string .= "," . $nets_index[$name]; } } print "<li><a href=\"#\" onClick=\"return selectSomeNets('" . $group_scan->get_net_group_name() . "','" . $sensor_string . "','" . $nets_string . "');\">" . $group_scan->get_net_group_name() . "</a>"; } $group_scan_list = Host_group_scan::get_list($conn, "WHERE plugin_id = " . NESSUS); foreach ($group_scan_list as $group_scan) { $host_group_sensors = Host_group::get_sensors($conn, $group_scan->get_host_group_name()); echo "\n<script>\n"; echo "var " . $group_scan->get_host_group_name() . " = true;\n"; echo "</script>\n"; $sensor_string = ""; foreach ($host_group_sensors as $hg_sensor) { $name = $hg_sensor->get_sensor_name(); if ($sensor_string == "") { $sensor_string .= $sensor_index[$name]; } else { $sensor_string .= "," . $sensor_index[$name]; } } $hosts_string = ""; $hosts = Host_group::get_hosts($conn, $group_scan->get_host_group_name(), NESSUS); foreach ($hosts as $host) { $name = $host->get_host_name($conn); if ($hosts_string == "") { $hosts_string .= $hosts_index[$name]; } else { $hosts_string .= "," . $hosts_index[$name]; } } print "<li><a href=\"#\" onClick=\"return selectSomeHosts('" . $group_scan->get_host_group_name() . "','" . $sensor_string . "','" . $hosts_string . "');\">" . $group_scan->get_host_group_name() . "</a>"; } ?> </ul> <form action="<?php echo $_SERVER["SCRIPT_NAME"]; ?> " method="POST"> <p> <?php echo _("Please adjust incident creation threshold, incidents will only be created for vulnerabilities whose risk level exceeds the threshold."); ?> <br/> <?php echo _("It is recommended to set a high level at the beginning in order to concentrate on more critical vulnerabilities first, lowering it after having solved/tagged them as false positivies."); ?> <br/> <?php echo _("Threshold configuration can be found at Configuration->Main, \"vulnerability_incident_threshold\"."); ?> <?php echo _("Current risk threshold is:"); ?> <b> <?php require_once 'ossim_conf.inc'; $conf = $GLOBALS["CONF"]; print $conf->get_conf("vulnerability_incident_threshold"); ?> </b> </p> <h4><center> (<?php echo _("Empty means all"); ?> ) </center></h4> <center><a href="#" onClick="return selectAll();"><?php echo _("Select / Unselect all"); ?> </a></center> <br/> <table width="100%" border="0" align="center"><tr><td> <input type="radio" name="groupType" value="sensor" checked onClick="selectGroup('sensor');"> Sensor <input type="radio" name="groupType" value="host" onClick="selectGroup('host');"> NetGroup / Nets / HostGroup / Hosts </td></tr> <tr><td> <div id="rowSensor"> <table width="100%" align="left" border="0"><tr> <?php for ($i = 1; $i <= $rows; $i++) { ?> <?php for ($a = 0; $a < $cols && $global_i < $num; $a++) { $sensor = $sensor_list[$global_i]; echo "<td width=\"" . intval(100 / $cols) . "%\">"; $all['sensors'][] = "sensor" . $global_i; ?> <div align="left"> <input align="left" type="checkbox" id="<?php echo "sensor" . $global_i; ?> " name="<?php echo "sensor" . $global_i; ?> " value="<?php echo $sensor->get_ip(); ?> " /><?php echo $sensor->get_name(); ?> </div></td> <?php $global_i++; } echo "</tr>\n"; ?> <?php } echo "</table>\n"; ?> </div> <div id="rowHost" style="display: none"> <table width="100%" align="left" border="0"> <tr> <th colspan="3">NetGroups</th></tr><tr> <?php $global_ng = 0; for ($i = 1; $i <= $rows_ng; $i++) { ?> <?php for ($a = 0; $a < $cols_full && $global_ng < $num_ng; $a++) { $netgroup = $net_group_list[$global_ng]; echo "<td width=\"" . intval(100 / $cols_full) . "%\">"; $all['netgroups'][] = "netgroup" . $global_ng; ?> <div align="left"> <input align="left" type="checkbox" id="<?php echo "netgroup" . $global_ng; ?> " name="netgroupList[]" value="<?php echo $netgroup->get_name(); ?> " /><?php echo $netgroup->get_name($conn); ?> </div></td> <?php $global_ng++; } echo "</tr>\n"; ?> <tr> <?php } ?> <th colspan="3">HostGroups</th></tr><tr> <?php $global_hg = 0; for ($i = 1; $i <= $rows_hg; $i++) { for ($a = 0; $a < $cols_full && $global_hg < $num_hg; $a++) { $hostgroup = $host_group_list[$global_hg]; echo "<td width=\"" . intval(100 / $cols_full) . "%\">"; $all['hostgroups'][] = "hostgroup" . $global_hg; ?> <div align="left"> <input align="left" type="checkbox" id="<?php echo "hostgroup" . $global_hg; ?> " name="hostgroupList[]" value="<?php echo $hostgroup->get_name(); ?> " /><?php echo $hostgroup->get_name($conn); ?> </div></td> <?php $global_hg++; } echo "</tr>\n"; ?> <tr> <?php } ?> <th colspan="3">Nets</th></tr><tr> <?php $global_ns = 0; for ($i = 1; $i <= $rows_ns; $i++) { ?> <?php for ($a = 0; $a < $cols_full && $global_ns < $num_ns; $a++) { $nets = $nets_list[$global_ns]; echo "<td width=\"" . intval(100 / $cols_full) . "%\">"; $all['nets'][] = "net" . $global_ns; ?> <div align="left"> <input align="left" type="checkbox" id="<?php echo "net" . $global_ns; ?> " name="netList[]" value="<?php echo $nets->get_name(); ?> " /><?php echo $nets->get_name($conn); ?> </div></td> <?php $global_ns++; } echo "</tr>\n"; ?> <tr> <?php } ?> <th colspan="3">Hosts</th></tr><tr> <?php $global_hs = 0; for ($i = 1; $i <= $rows_hs; $i++) { ?> <?php for ($a = 0; $a < $cols_full && $global_hs < $num_hs; $a++) { $hosts = $hosts_list[$global_hs]; echo "<td width=\"" . intval(100 / $cols_full) . "%\">"; $all['hosts'][] = "host" . $global_hs; ?> <div align="left"> <input align="left" type="checkbox" id="<?php echo "host" . $global_hs; ?> " name="hostList[]" value="<?php echo $hosts->get_host_ip(); ?> " /><?php echo $hosts->get_name($conn); ?> </div></td> <?php $global_hs++; } echo "</tr>\n"; ?> <?php } echo "</table>\n"; ?> </div> </td></tr></table> <br> <center> <input type="hidden" name="nsensors" value="<?php echo $global_i; ?> " /> <input type="Submit" class="button" value="<?php echo _("Submit"); ?> "> </center> </form> <center><a href="index.php"> <?php echo gettext("Back"); ?> </a></center> <script> var check_sensors = true; var check_nethost = true; var scanType = 'sensor'; function selectAll() { if (scanType == 'sensor') { <?php if (count($all['sensors']) != 0) { foreach ($all['sensors'] as $id) { ?> document.getElementById('<?php echo $id; ?> ').checked = check_sensors; <?php } } ?> check_sensors = check_sensors == false ? true : false; } else { <?php if (count($all['netgroups']) != 0) { foreach ($all['netgroups'] as $id) { ?> document.getElementById('<?php echo $id; ?> ').checked = check_nethost; <?php } } ?> <?php if (count($all['hostgroups']) != 0) { foreach ($all['hostgroups'] as $id) { ?> document.getElementById('<?php echo $id; ?> ').checked = check_nethost; <?php } } ?> <?php if (count($all['nets']) != 0) { foreach ($all['nets'] as $id) { ?> document.getElementById('<?php echo $id; ?> ').checked = check_nethost; <?php } } ?> <?php if (count($all['hosts']) != 0) { foreach ($all['hosts'] as $id) { ?> document.getElementById('<?php echo $id; ?> ').checked = check_nethost; <?php } } ?> check_nethost = check_nethost == false ? true : false; } return false; } function selectSomeNets(name, identifiersSensors, identifiersNets) { if (identifiersSensors.length != 0) { arrayOfStringsSensor = identifiersSensors.split(","); for (var i=0; i < arrayOfStringsSensor.length; i++) { document.getElementById("sensor" + arrayOfStringsSensor[i]).checked = window[name]; } } if (identifiersNets.length != 0) { arrayOfStringsNets = identifiersNets.split(","); for (var i=0; i < arrayOfStringsNets.length; i++) { document.getElementById("net" + arrayOfStringsNets[i]).checked = window[name]; } } window[name] = window[name] == false ? true : false; return false; } function selectSomeHosts(name, identifiersSensors, identifiersHosts) { if (identifiersSensors.length != 0) { arrayOfStringsSensor = identifiersSensors.split(","); for (var i=0; i < arrayOfStringsSensor.length; i++) { document.getElementById("sensor" + arrayOfStringsSensor[i]).checked = window[name]; } } if (identifiersHosts.length != 0) { arrayOfStringsHosts = identifiersHosts.split(","); for (var i=0; i < arrayOfStringsHosts.length; i++) { document.getElementById("host" + arrayOfStringsHosts[i]).checked = window[name]; } } window[name] = window[name] == false ? true : false; return false; } function selectGroup(category) { if (category == 'sensor') { document.getElementById("rowHost").style.display = 'none'; document.getElementById("rowSensor").style.display = 'block'; } else { document.getElementById("rowHost").style.display = 'block'; document.getElementById("rowSensor").style.display = 'none'; } scanType = category; } </script> </body> </html> <?php }
require_once 'classes/Host_scan.inc'; $host_list = Host_group::get_hosts($conn, $name); foreach ($host_list as $host) { $ip = $host->get_host_ip(); if (Host::can_delete($conn, $ip)) { if (Host_scan::in_host_scan($conn, $ip, 2007)) { Host_scan::delete($conn, $ip, 2007); } Host_scan::delete($conn, $ip, 3001); Host::delete($conn, $ip); } } } // Host_group_scan::delete($conn, $name, 3001); Host_group::delete($conn, $name); } else { echo "ERROR_CANNOT"; } $db->close($conn); ?> <p> <?php echo gettext("Host group deleted"); ?> </p> <p><a href="hostgroup.php"><?php echo gettext("Back"); ?> </a></p>
foreach ($group_scan_list as $group_scan) { $host_group_sensors = Host_group::get_sensors($conn, $group_scan->get_host_group_name()); echo "\n<script>\n"; echo "var " . $group_scan->get_host_group_name() . " = true;\n"; echo "</script>\n"; $sensor_string = ""; foreach ($host_group_sensors as $hg_sensor) { $name = $hg_sensor->get_sensor_name(); if ($sensor_string == "") { $sensor_string .= $sensor_index[$name]; } else { $sensor_string .= "," . $sensor_index[$name]; } } $hosts_string = ""; $hosts = Host_group::get_hosts($conn, $group_scan->get_host_group_name(), NESSUS); foreach ($hosts as $host) { $name = $host->get_host_name($conn); if ($hosts_string == "") { $hosts_string .= $hosts_index[$name]; } else { $hosts_string .= "," . $hosts_index[$name]; } } print "<li><a href=\"#\" onClick=\"return selectSomeHosts('" . $group_scan->get_host_group_name() . "','" . $sensor_string . "','" . $hosts_string . "');\">" . $group_scan->get_host_group_name() . "</a>"; } ?> </ul> <form action="<?php echo $_SERVER["SCRIPT_NAME"];
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>";
function get_assets($conn, $name, $type, $host_types) { // in_assets first $in_assets = is_in_assets($conn, $name, $type); // Asset values $ips = $name; $what = "name"; if (in_array($type, $host_types)) { if ($type == "host") { $what = "hostname"; } $query = "select ip from {$type} where {$what} = ?"; $params = array($name); if ($rs3 =& $conn->Execute($query, $params)) { $name = $rs3->fields["ip"]; if ($rs3->EOF) { $in_assets = 0; } } // Related sensor $sensor = $name; if ($type == "host") { require_once 'classes/Host.inc'; $sensors = Host::get_related_sensors($conn, $name, false); $sensor = $sensors[0] != "" ? $sensors[0] : $name; } } elseif ($type == "net") { $query = "select ips from net where name = ?"; $params = array($name); if ($rs3 =& $conn->Execute($query, $params)) { $ips = $rs3->fields["ips"]; if ($rs3->EOF) { $in_assets = 0; } } // related sensor require_once 'classes/Net.inc'; $sensors = Net::get_related_sensors($conn, $name); $sensor = $sensors[0] != "" ? $sensors[0] : ""; } elseif ($type == "host_group") { $query = "select host_ip from host_group_reference where host_group_name = ?"; $params = array($name); if ($rs3 =& $conn->Execute($query, $params)) { $iphg = array(); while (!$rs3->EOF) { $iphg[] = "'" . $rs3->fields["host_ip"] . "'"; $rs3->MoveNext(); } $ips = count($iphg) > 0 ? implode(",", $iphg) : "'0.0.0.0'"; if (count($iphg) == 0) { $in_assets = 0; } } // related sensor{ require_once 'classes/Host_group.inc'; $sensors = Host_group::get_related_sensors($conn, $name); $sensor = $sensors[0] != "" ? $sensors[0] : $name; } return array($name, $sensor, $type, $ips, $what, $in_assets); }