$h_list .= '{ txt:"' . $_ip . '", id: "' . Asset_host_ips::ip2ulong($_ip) . '" },'; } } } // Protocol list if ($protocol_list = Protocol::get_list()) { echo "var protocols = new Array(" . count($protocol_list) . ")\n"; foreach ($protocol_list as $proto) { //$_SESSION[$id] = $plugin->get_name(); echo "protocols['proto_" . $proto['id'] . "'] = '" . $proto['name'] . "'\n"; //Load available protocols (Autocompleted) $p_list .= '{ txt: "Protocol:' . $proto['name'] . '", id: "' . $proto['id'] . '" },'; } } //Port list (Autocompleted) if ($port_list = Port::get_list($conn, " AND protocol_name='tcp'")) { foreach ($port_list as $port) { $prt_list .= '{ txt:"' . $port->get_port_number() . " - " . $port->get_service() . '", id: "' . $port->get_port_number() . '" },'; } } // Plugin list $sids = array(); if ($plugin_list = Plugin::get_list($conn, "")) { echo "var plugins = new Array(" . count($plugin_list) . ")\n"; foreach ($plugin_list as $plugin) { $sids[$plugin->get_name()] = $plugin->get_id(); //$_SESSION[$id] = $plugin->get_name(); echo "plugins['id_" . $plugin->get_id() . "'] = '" . $plugin->get_name() . "';\n"; echo "plugins['id_" . $plugin->get_name() . "'] = '" . $plugin->get_name() . "';\n"; } }
ossim_valid($rp, OSS_DIGIT, OSS_NULLABLE, 'illegal:' . _("rp")); if (ossim_error()) { echo "<rows>\n<page>1</page>\n<total>0</total>\n</rows>\n"; exit; } if (!empty($order)) { $order .= POST('sortorder') == "asc" ? "" : " desc"; } else { $order = "port_number"; } $start = ($page - 1) * $rp; $limit = "LIMIT {$start}, {$rp}"; $db = new ossim_db(); $conn = $db->connect(); $xml = ""; $port_list = Port::get_list($conn, " AND port_number > 0", "ORDER BY {$order} {$limit}"); if ($port_list[0]) { $total = $port_list[0]->get_foundrows(); if ($total == 0) { $total = count($port_list); } } else { $total = 0; } $xml .= "<rows>\n"; $xml .= "<page>{$page}</page>\n"; $xml .= "<total>{$total}</total>\n"; foreach ($port_list as $port) { $port_number = $port->get_port_number(); $protocol = $port->get_protocol_name(); $service = $port->get_service() == '' ? " " : $port->get_service();
$prev = ""; $fnd = array(); if (preg_match("/(.*=)(.*\\|)(.*)/", $str, $fnd)) { $prev = $fnd[2]; $str = $fnd[1] . $fnd[3]; } $data = array(); $top = 10; $tag_typing = 0; if (trim($str) != "") { list($sensors, $hosts) = Host::get_ips_and_hostname($conn); $nets = Net::get_list($conn); $plugins = GetPlugins($conn); $sourcetypes = GetSourceTypes($conn); $plugingroups = Plugingroup::get_list($conn); $ports = Port::get_list($conn); $categories = GetPluginCategories($conn); $subcategories = GetPluginSubCategories($conn, $categories); // Typing a tag if (preg_match("/^(sensor|src|dst|plugin|datasource|plugingroup|dsgroup|src_port|dst_port|product_type|event_category|category|data)(\\!?\\=)(.*)/i", $str, $found)) { $tag_typing = 1; $str = $found[3]; $op = $found[2]; if ($str == "") { $str = "."; } $qstr = $str; if ($found[1] == "sensor") { foreach ($sensors as $ip => $name) { if ((preg_match("/^{$qstr}/i", $name) || preg_match("/^{$qstr}/i", $ip)) && !preg_match("/{$name}/i", $fnd[2]) && count($data) < $top && $current_query["sensor{$op}{$ip}"] == "") { $data[] = array("name" => "<b>sensor</b>{$op}{$prev}{$name}");
if (!isset($_POST['ajax_validation_all']) || POST('ajax_validation_all') == FALSE) { if (!Token::verify('tk_form_p', POST('token'))) { Token::show_error(_("Action not allowed")); exit; } } $port = intval(POST('port')); $protocol = POST('protocol'); $service = POST('service'); $descr = POST('descr'); $ctx = POST('ctx'); $validation_errors = validate_form_fields('POST', $validate); if (empty($validation_errors)) { $db = new ossim_db(); $conn = $db->connect(); $ports = Port::get_list($conn, " AND port_number LIKE '{$port}' AND protocol_name='{$protocol}' AND ctx=UNHEX('{$ctx}')"); $db->close(); if (count($ports) >= 1) { $validation_errors['port'] = _("Port {$port} already exists"); } } $data['status'] = 'OK'; $data['data'] = $validation_errors; if (POST('ajax_validation_all') == TRUE) { if (is_array($validation_errors) && !empty($validation_errors)) { $data['status'] = 'error'; echo json_encode($data); } else { $data['status'] = 'OK'; echo json_encode($data); }
* On Debian GNU/Linux systems, the complete text of the GNU General * Public License can be found in `/usr/share/common-licenses/GPL-2'. * * Otherwise you can read it here: http://www.gnu.org/licenses/gpl-2.0.txt * */ require_once 'av_init.php'; Session::logcheck("configuration-menu", "PolicyPorts"); $search = GET('q'); $limit = GET('limit'); $protocol = GET('protocol'); $ctx = GET('ctx'); ossim_valid($search, OSS_NOECHARS, OSS_ALPHA, OSS_SCORE, OSS_PUNC, 'illegal:' . _("search")); ossim_valid($limit, OSS_DIGIT, 'illegal:' . _("limit")); ossim_valid($protocol, OSS_LETTER, 'illegal:' . _("protocol")); ossim_valid($ctx, OSS_HEX, 'illegal:' . _("entity")); if (ossim_error()) { die; } //create filter and order $where = " AND service like '%" . $search . "%' and protocol_name = '" . $protocol . "' AND ctx = UNHEX('{$ctx}') "; $order = "order by service limit " . $limit; // connect to database $db = new ossim_db(); $conn = $db->connect(); // search ports $ports = Port::get_list($conn, $where, $order); $db->close(); foreach ($ports as $port) { echo $port->get_service() . "\n"; }
* */ require_once 'av_init.php'; Session::logcheck('configuration-menu', 'PolicyPorts'); $db = new ossim_db(); $conn = $db->connect(); $id = GET('id'); $id = explode('@@', $id); $port_number = $id[0]; $protocol_name = $id[1]; ossim_valid($port_number, OSS_PORT, 'illegal:' . _('Port Number')); ossim_valid($protocol_name, OSS_PROTOCOL, 'illegal:' . _("Protocol Name")); if (ossim_error()) { die(ossim_error()); } if ($port_list = Port::get_list($conn, " AND port_number='{$port_number}' and protocol_name='{$protocol_name}'")) { $port_selected = $port_list[0]; } $port = $port_selected->get_port_number(); $protocol = $port_selected->get_protocol_name(); $service = $port_selected->get_service(); $descr = $port_selected->get_descr(); $ctx = $port_selected->get_ctx(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title><?php echo _("OSSIM Framework");
require_once 'classes/Security.inc'; Session::logcheck("MenuPolicy", "PolicyPorts"); //Autocomplete Ports $db = new ossim_db(); $conn = $db->connect(); $ports = array(); $port_list = array(); $arr_ports_input = array(); $ports_input = ""; $update = intval(GET('update')); $style_success = "style='display: none;'"; if ($update == 1) { $success_message = gettext("Port Group succesfully updated"); $style_success = "style='display: block;text-align:center;'"; } if ($port_list = Port::get_list($conn)) { foreach ($port_list as $port) { $ports[] = $port->get_port_number() . " - " . $port->get_protocol_name(); } } foreach ($ports as $k => $v) { $arr_ports_input[] = '{ txt:"' . $v . '", id: "' . $v . '" }'; } $ports_input = implode(",", $arr_ports_input); if (isset($_SESSION['_portgroup'])) { $pgname = $_SESSION['_portgroup']['pgname']; $actives_ports = $_SESSION['_portgroup']['actives_ports']; $descr = $_SESSION['_portgroup']['descr']; unset($_SESSION['_portgroup']); } else { $pgname = GET('portname');
$validation_errors = validate_form_fields('POST', $validate); if (is_array($validation_errors) && !empty($validation_errors)) { //Formatted message $error_msg = '<div>' . _('The following errors occurred') . ":</div>\n <div style='padding: 5px;'>" . implode('<br/>', $validation_errors) . '</div>'; Util::response_bad_request($error_msg); } else { try { $db = new ossim_db(); $conn = $db->connect(); $asset_id = POST('asset_id'); $protocol = POST('s_protocol'); $protocol_name = Protocol::get_protocol_by_number($protocol); $port = POST('s_port'); $service = POST('s_name'); $ctx = Asset_host::get_ctx_by_id($conn, $asset_id); $n_ports = Port::get_list($conn, " AND port_number = {$port} and protocol_name = '{$protocol_name}'"); if (count($n_ports) == 0) { Port::insert($conn, $port, $protocol_name, $service, '', $ctx); } else { $data['status'] = 'warning'; $data['data'] = _('Warning! This port has already been added'); } $db->close(); } catch (Exception $e) { Util::response_bad_request(_('Error! Your changes could not be saved')); } } break; //Asset properties, MAC address, Software and Services //Asset properties, MAC address, Software and Services case 'new_property':
$validate = array("port" => array("validation" => "OSS_PORT", "e_message" => 'illegal:' . _("Port")), "protocol" => array("validation" => "OSS_PROTOCOL", "e_message" => 'illegal:' . _("Protocol")), "service" => array("validation" => "OSS_ALPHA, OSS_PUNC", "e_message" => 'illegal:' . _("Service")), "descr" => array("validation" => "OSS_NULLABLE, OSS_AT, OSS_TEXT", "e_message" => 'illegal:' . _("Description"))); if (GET('ajax_validation') == true) { $validation_errors = validate_form_fields('GET', $validate); if ($validation_errors == 1) { echo 1; } else { if (empty($validation_errors)) { echo 0; } else { echo $validation_errors[0]; } } exit; } else { $validation_errors = validate_form_fields('POST', $validate); $ports = Port::get_list($conn, $where = "WHERE port_number LIKE '{$port}' AND protocol_name=\"{$protocol}\""); $exists_port = count($ports) > 1 ? true : false; if ($validation_errors == 1 || is_array($validation_errors) && !empty($validation_errors) || $exists_port == true) { $error = true; $message_error = array(); if ($exists_port >= 1) { $message_error[] = _("Port {$port} already exists"); } if (is_array($validation_errors) && !empty($validation_errors)) { $message_error = array_merge($message_error, $validation_errors); } else { if ($validation_errors == 1) { $message_error[] = _("Invalid send method"); } } }
function getPortList() { global $conn; if ($port_list = Port::get_list($conn, '', '')) { return $port_list; } return ""; }
if (ossim_error()) { $error_message = "<div style='padding-left: 10px'>" . ossim_get_error_clean() . "</div>"; } else { $date = strftime("%Y-%m-%d %H:%M:%S"); if ($nservice != '') { $serviceName = $nservice; } else { if ($ports[$port_number . " - " . $protocol_name] != "") { $serviceName = $ports[$port_number . " - " . $protocol_name]; } else { $serviceName = 'unknown'; } } // Insert new port $chport = array(); $chport = Port::get_list($conn, "where port_number = {$port_number} and protocol_name = '{$protocol_name}'"); if (count($chport) == 0) { Port::insert($conn, $port_number, $protocol_name, $serviceName, ""); } $protocol = $protocol_ids[$protocol_name]; Host_services::insert($conn, $ip, $port_number, $date, $_SERVER["SERVER_ADDR"], $protocol, $serviceName, "unknown", "unknown", 1, $newport_nagios); // origin = 0 (pads), origin = 1 (nmap) } } if ($error_message != null) { $style = "style='display: block;'"; $error_message = "<div style='padding-left: 15px;'>{$error_message}</div>"; ossim_clean_error(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">