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); }
} if (POST('insert')) { if ($error == true) { $txt_error = "<div>" . _("We Found the following errors") . ":</div><div style='padding:10px;'>" . implode("<br/>", $message_error) . "</div>"; Util::print_error($txt_error); Util::make_form("POST", "newhostgroupform.php?" . $get_param); die; } $db = new ossim_db(); $conn = $db->connect(); /* NESSUS - DEPRECATED Host_group_scan::delete($conn, $hgname, 3001, 0); Host_group_scan::insert($conn, $hgname, 3001, 0); */ Host_group::insert($conn, $hgname, $threshold_c, $threshold_a, $rrd_profile, $sensors, $hosts, $descr); Host_group_scan::delete($conn, $hgname, 3001, 0); if ($nagios) { if (!Host_group_scan::in_host_group_scan($conn, $hgname, 2007)) { Host_group_scan::insert($conn, $hgname, 2007, 0, $hosts, $sensors); } } else { if (Host_group_scan::in_host_group_scan($conn, $hgname, 2007)) { Host_group_scan::delete($conn, $hgname, 2007); } } $db->close($conn); Util::clean_json_cache_files("(policy|vulnmeter|hostgroup)"); } if (isset($_SESSION['_hostgroup'])) { unset($_SESSION['_hostgroup']);