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=700,height=460,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 open_help (help_id, home_url, id_user) { open (home_url+"general/pandora_help.php?id="+help_id+"&id_user="+id_user, "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; }; /** * Fill up select box with id "module" with modules after agent has been selected * * @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 (event, id_agent, selected) { if (id_agent == undefined) id_agent = this.value; $('#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": 1, "id_agent": id_agent }, 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['id_agente_modulo'])); $('#module').fadeIn ('normal'); }); if (selected != undefined) $('#module').attr ('value', selected); $('#module').removeAttr('disabled'); }, "json" ); } /** * 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)) { var noneText = $("#none_text").html(); //Trick for catch the translate text. 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)); } } jQuery.each (data, function (i, val) { var s = js_html_entity_decode(val); $('#module') .append ($('') .html (s) .attr ("value", i) .attr("title", s)); $('#module').fadeIn ('normal'); }); 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'; } 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 }, 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", val)); $('#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_events(name) { $('.' + name + '_toggler').click(function() { var value = $('#text-' + name + '_text').val(); var count = $('#' + name + '_select option') .filter(function(i, item) { if (Number($(item).val()) == Number(value)) return true; else return false; }) .length; if (count != 1) { $('#' + name + '_select') .append($("