/* global $ */ /* exported load_modal */ var ENTERPRISE_DIR = "enterprise"; /* Function to hide/unhide a specific Div id */ function toggleDiv(divid) { if (document.getElementById(divid).style.display == "none") { document.getElementById(divid).style.display = "block"; } else { document.getElementById(divid).style.display = "none"; } } function winopeng(url, wid) { open( url, wid, "width=1000,height=550,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes" ); // WARNING !! Internet Explorer DOESNT SUPPORT "-" CARACTERS IN WINDOW HANDLE VARIABLE status = wid; } function winopeng_var(url, wid, width, height) { open( url, wid, "width=" + width + ",height=" + height + ",status=no,toolbar=no,menubar=no,scrollbar=yes" ); // WARNING !! Internet Explorer DOESNT SUPPORT "-" CARACTERS IN WINDOW HANDLE VARIABLE status = wid; } function newTabjs(content) { content = atob(content); var printWindow = window.open(""); printWindow.document.body.innerHTML += "
" + content + "
"; } function open_help(url) { if (!navigator.onLine) { alert( "The help system could not be started. Please, check your network connection." ); return; } if (url == "") { alert( "The help system is currently under maintenance. Sorry for the inconvenience." ); return; } open( url, "pandorahelp", "width=650,height=500,status=0,toolbar=0,menubar=0,scrollbars=1,location=0" ); } /** * Decode HTML entities into characters. Useful when receiving something from AJAX * * @param str String to convert * * @retval str with entities decoded */ function js_html_entity_decode(str) { if (!str) return ""; str2 = str .replace(//g, ">") .replace(/</g, "<") .replace(/>/g, ">") .replace(/\/g, "\\") .replace(/"/g, '"') .replace(/'/g, "'") .replace(/&/g, "&") .replace(/ /g, " ") .replace(/ /g, "\r") .replace(/ /g, "\n"); return str2; } /** * Function to search an element in an array. * * Extends the array object to use it like a method in an array object. Example: * a = Array (4, 7, 9); alert (a.in_array (4)); // true alert (a.in_array (5)); // false */ Array.prototype.in_array = function() { for (var j in this) { if (this[j] == arguments[0]) return true; } return false; }; /** * Util for check is empty object * * @param obj the object to check * @returns {Boolean} True it is empty */ function isEmptyObject(obj) { for (var prop in obj) { if (obj.hasOwnProperty(prop)) return false; } return true; } /** * Fill up select box with id "module" with modules after agent has been selected, but this not empty the select box.s * * @param event that has been triggered * @param id_agent Agent ID that has been selected * @param selected Which module(s) have to be selected */ function agent_changed_by_multiple_agents(event, id_agent, selected) { // Hack to avoid certain module types var module_types_excluded = []; if (typeof $("input.module_types_excluded") !== "undefined") { try { $("input.module_types_excluded").each(function(index, el) { var module_type = parseInt($(el).val()); if (module_type !== NaN) module_types_excluded.push(module_type); }); } catch (error) {} } var module_status = -1; if (typeof $("#status_module") !== "undefined") { try { module_status = $("#status_module").val(); } catch (error) {} } // Module name var module_name = $("#text-module_filter").val(); var idAgents = Array(); jQuery.each($("#id_agents option:selected"), function(i, val) { //val() because the var is same idAgents.push($(val).val()); }); var tags_to_search = $("#tags1").val(); //Hack to find only enabled modules //Pass a flag as global var find_modules = "all"; if ( typeof show_only_enabled_modules !== "undefined" && show_only_enabled_modules ) { find_modules = "enabled"; } var selection_mode = $("#modules_selection_mode").val(); if (typeof selection_mode === "undefined") { selection_mode = "common"; } var serialized = $("#hidden-serialized").val(); if (typeof serialized === "undefined") { serialized = ""; } $("#module") .prop("disabled", true) .empty() .append( $("") .html("Loading...") .attr("value", 0) ); // Check if homedir was received like a JSON var homedir = "."; var id_server = 0; if (typeof event !== "undefined" && typeof event.data !== "undefined") { if (event.data != null) { if (typeof event.data !== "undefined") { if (typeof event.data.homedir !== "undefined") { homedir = event.data.homedir; } if ( typeof event.data.metaconsole !== "undefined" && event.data.metaconsole ) { id_server = $("#" + event.data.id_server).val(); } } } } jQuery.post( homedir + "/ajax.php", { page: "operation/agentes/ver_agente", get_agent_modules_json_for_multiple_agents: 1, "id_agent[]": idAgents, "tags[]": tags_to_search, all: find_modules, "module_types_excluded[]": module_types_excluded, name: module_name, selection_mode: selection_mode, serialized: serialized, id_server: id_server, status_module: module_status }, function(data) { $("#module").empty(); if (isEmptyObject(data)) { //Trick for catch the translate text. var noneText = $("#id_agents").val() === null ? $("#select_agent_first_text").html() : $("#none_text").html(); if (noneText == null) { noneText = "None"; } $("#module").append( $("") .html(noneText) .attr("None", "") .prop("selected", true) ); return; } if (typeof $(document).data("text_for_module") != "undefined") { $("#module").append( $("") .html($(document).data("text_for_module")) .attr("value", 0) .prop("selected", true) ); } else { if (typeof data["any_text"] != "undefined") { $("#module").append( $("") .html(data["any_text"]) .attr("value", 0) .prop("selected", true) ); } else { var anyText = $("#any_text").html(); //Trick for catch the translate text. if (anyText == null) { anyText = "Any"; } $("#module").append( $("") .html(anyText) .attr("value", 0) .prop("selected", true) ); } } var all_common_modules = []; $.each(data, function(i, val) { var s = js_html_entity_decode(val); $("#module").append( $("") .html(s) .attr("value", i) .attr("title", s) ); all_common_modules.push(i); $("#module").fadeIn("normal"); }); $("#hidden-all_common_modules").val(all_common_modules.toString()); if (typeof selected !== "undefined") $("#module").attr("value", selected); $("#module") .css("max-width", "") .prop("disabled", false); if (typeof function_hook_loaded_module_list == "function") { function_hook_loaded_module_list(); } }, "json" ); } /** * Fill up select box with id "module" with modules with alerts of one template * after agent has been selected, but this not empty the select box.s * * @param event that has been triggered * @param id_agent Agent ID that has been selected * @param selected Which module(s) have to be selected */ function agent_changed_by_multiple_agents_with_alerts( event, id_agent, selected ) { var idAgents = Array(); jQuery.each($("#id_agents option:selected"), function(i, val) { //val() because the var is same idAgents.push($(val).val()); }); var selection_mode = $("#modules_selection_mode").val(); if (selection_mode == undefined) { selection_mode = "common"; } template = $("#id_alert_template option:selected").val(); $("#module").attr("disabled", 1); $("#module").empty(); $("#module").append( $("") .html("Loading...") .attr("value", 0) ); jQuery.post( "ajax.php", { page: "operation/agentes/ver_agente", get_agent_modules_multiple_alerts_json_for_multiple_agents: 1, template: template, "id_agent[]": idAgents, selection_mode: selection_mode }, function(data) { $("#module").empty(); if (typeof $(document).data("text_for_module") != "undefined") { $("#module").append( $("") .html($(document).data("text_for_module")) .attr("value", 0) .prop("selected", true) ); } else { if (typeof data["any_text"] != "undefined") { $("#module").append( $("") .html(data["any_text"]) .attr("value", 0) .prop("selected", true) ); } else { var anyText = $("#any_text").html(); //Trick for catch the translate text. if (anyText == null) { anyText = "Any"; } $("#module").append( $("") .html(anyText) .attr("value", 0) .prop("selected", true) ); } } jQuery.each(data, function(i, val) { s = js_html_entity_decode(val); $("#module").append( $("") .html(s) .attr("value", val) ); $("#module").fadeIn("normal"); }); if (selected != undefined) $("#module").attr("value", selected); $("#module").removeAttr("disabled"); }, "json" ); } /** * Fill up select box with id "module" with modules with alerts of one or more templates * before agent has been selected, but this not empty the select box.s * * @param event that has been triggered * @param id_agent Agent ID that has been selected * @param selected Which module(s) have to be selected */ function alert_templates_changed_by_multiple_agents_with_alerts( event, id_agent, selected ) { var idAgents = Array(); jQuery.each($("#id_agents option:selected"), function(i, val) { //val() because the var is same idAgents.push($(val).val()); }); var selection_mode = $("#modules_selection_mode").val(); if (selection_mode == undefined) { selection_mode = "common"; } templates = Array(); jQuery.each($("#id_alert_templates option:selected"), function(i, val) { //val() because the var is same templates.push($(val).val()); }); $("#module").attr("disabled", 1); $("#module").empty(); $("#module").append( $("") .html("Loading...") .attr("value", 0) ); jQuery.post( "ajax.php", { page: "operation/agentes/ver_agente", get_agent_modules_alerts_json_for_multiple_agents: 1, "templates[]": templates, "id_agent[]": idAgents, selection_mode: selection_mode }, function(data) { $("#module").empty(); if (typeof $(document).data("text_for_module") != "undefined") { $("#module").append( $("") .html($(document).data("text_for_module")) .attr("value", 0) .prop("selected", true) ); } else { if (typeof data["any_text"] != "undefined") { $("#module").append( $("") .html(data["any_text"]) .attr("value", 0) .prop("selected", true) ); } else { var anyText = $("#any_text").html(); //Trick for catch the translate text. if (anyText == null) { anyText = "Any"; } $("#module").append( $("") .html(anyText) .attr("value", 0) .prop("selected", true) ); } } jQuery.each(data, function(i, val) { s = js_html_entity_decode(val); $("#module").append( $("") .html(s) .attr("value", val) ); $("#module").fadeIn("normal"); }); if (selected != undefined) $("#module").attr("value", selected); $("#module").removeAttr("disabled"); }, "json" ); } /** * Fill up select box with id "agent" with agents after module has been selected, but this not empty the select box.s * * @param event that has been triggered * @param id_module Module ID that has been selected * @param selected Which agent(s) have to be selected */ function module_changed_by_multiple_modules(event, id_module, selected) { var idModules = Array(); jQuery.each($("#module_name option:selected"), function(i, val) { //val() because the var is same idModules.push($(val).val()); }); $("#agents").attr("disabled", 1); $("#agents").empty(); $("#agents").append( $("") .html("Loading...") .attr("value", 0) ); var status_module = -1; if (typeof $("#status_module") !== "undefined") { try { status_module = $("#status_module").val(); } catch (error) {} } var selection_mode = $("#agents_selection_mode").val(); if (selection_mode == undefined) { selection_mode = "common"; } var tags_selected = []; var tags_to_search = $("#tags").val(); if (tags_to_search != null) { if (tags_to_search[0] != -1) { tags_selected = tags_to_search; } } jQuery.post( "ajax.php", { page: "operation/agentes/ver_agente", get_agents_json_for_multiple_modules: 1, status_module: status_module, "module_name[]": idModules, selection_mode: selection_mode, tags: tags_selected }, function(data) { $("#agents").append( $("") .html("Loading...") .attr("value", 0) ); $("#agents").empty(); if (isEmptyObject(data)) { var noneText = $("#none_text").html(); //Trick for catch the translate text. if (noneText == null) { noneText = "None"; } $("#agents").append( $("") .html(noneText) .attr("None", "") .prop("selected", true) ); return; } if (typeof $(document).data("text_for_module") != "undefined") { $("#agents").append( $("") .html($(document).data("text_for_module")) .attr("value", 0) .prop("selected", true) ); } else { if (typeof data["any_text"] != "undefined") { $("#agents").append( $("") .html(data["any_text"]) .attr("value", 0) .prop("selected", true) ); } else { var anyText = $("#any_text").html(); //Trick for catch the translate text. if (anyText == null) { anyText = "Any"; } $("#agents").append( $("") .html(anyText) .attr("value", 0) .prop("selected", true) ); } } jQuery.each(data, function(i, val) { s = js_html_entity_decode(val); $("#agents").append( $("") .html(s) .attr("value", i) ); $("#agents").fadeIn("normal"); }); if (selected != undefined) $("#agents").attr("value", selected); $("#agents").removeAttr("disabled"); }, "json" ); } /** * Fill up select box with id "module" with modules after agent has been selected, but this not empty the select box.s * * @param event that has been triggered * @param id_agent Agent ID that has been selected * @param selected Which module(s) have to be selected */ function agent_changed_by_multiple_agents_id(event, id_agent, selected) { var idAgents = Array(); jQuery.each($("#id_agents option:selected"), function(i, val) { //val() because the var is same idAgents.push($(val).val()); }); $("#module").attr("disabled", 1); $("#module").empty(); $("#module").append( $("") .html("Loading...") .attr("value", 0) ); jQuery.post( "ajax.php", { page: "operation/agentes/ver_agente", get_agent_modules_json_for_multiple_agents_id: 1, "id_agent[]": idAgents }, function(data) { $("#module").empty(); if (typeof $(document).data("text_for_module") != "undefined") { $("#module").append( $("") .html($(document).data("text_for_module")) .attr("value", 0) .prop("selected", true) ); } else { if (typeof data["any_text"] != "undefined") { $("#module").append( $("") .html(data["any_text"]) .attr("value", 0) .prop("selected", true) ); } else { var anyText = $("#any_text").html(); //Trick for catch the translate text. if (anyText == null) { anyText = "Any"; } $("#module").append( $("") .html(anyText) .attr("value", 0) .prop("selected", true) ); } } jQuery.each(data, function(i, val) { s = js_html_entity_decode(val["nombre"]); //$('#module').append ($('').html (s).attr ("value", val)); $("#module").append( $("") .html(s) .attr("value", val["id_agente_modulo"]) ); $("#module").fadeIn("normal"); }); if (selected != undefined) $("#module").attr("value", selected); $("#module").removeAttr("disabled"); }, "json" ); } function post_process_select_init(name) { // Manual mode is hidden by default $("#" + name + "_manual").hide(); $("#" + name + "_default").show(); } function post_process_select_init_unit(name, selected) { // Manual mode is hidden by default $("#" + name + "_manual").hide(); $("#" + name + "_default").show(); if (selected != "") { var select_or_text = false; $("#" + name + "_select option").each(function(i, item) { if ($(item).val() == selected) { select_or_text = true; return false; } }); if (select_or_text) { $("#" + name + "_select option[value='" + selected + "']").attr( "selected", true ); $("#text-" + name + "_text").val(""); } else { $("#" + name + "_select option[value=0]").attr("selected", true); $("#" + name + "_default").hide(); $("#" + name + "_manual").show(); } } else { $("#" + name + "_select option[value=0]").attr("selected", true); $("#" + name + "_default").hide(); $("#" + name + "_manual").show(); } $("#" + name + "_select").change(function() { var value = $("#" + name + "_select").val(); $("#" + name + "_select option[value='" + value + "']").attr( "selected", true ); }); } function post_process_select_events_unit(name, selected) { $("." + name + "_toggler").click(function() { var value = $("#text-" + name + "_text").val(); var count = $("#" + name + "_select option").filter(function(i, item) { if ($(item).val() == value) return true; else return false; }).length; if (count != 1) { $("#" + name + "_select").append( $("