Merge branch 'ent-4149-Poner-mensaje-sin-eventos-en-la-extension-de-pandora-si-no-hay-eventos' into 'develop'

updated chrome events extension

See merge request artica/pandorafms!2622
This commit is contained in:
Alejandro Fraguas 2019-08-20 13:12:51 +02:00
commit b390c6cb26
2 changed files with 184 additions and 171 deletions

View File

@ -1,170 +1,183 @@
var max_events; var max_events;
var bg; var bg;
$(document).ready(function(){ $(document).ready(function() {
max_events=localStorage["events"]; max_events = localStorage["events"];
if(localStorage["events"]==undefined){ if (localStorage["events"] == undefined) {
localStorage["events"]="20"; localStorage["events"] = "20";
} }
bg=chrome.extension.getBackgroundPage(); bg = chrome.extension.getBackgroundPage();
// Display the information // Display the information
if (bg.fetchEvents().length == 0) { if (bg.fetchEvents().length == 0) {
showError("Error in fetching data!! Check your internet connection"); showError("No events");
} else { } else {
showEvents(); showEvents();
} }
// Adding buttons listeners // Adding buttons listeners
document.getElementById("m_refresh").addEventListener("click", mrefresh); document.getElementById("m_refresh").addEventListener("click", mrefresh);
// Added listener to background messages // Added listener to background messages
chrome.runtime.onMessage.addListener(function(message,sender,sendResponse){ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
switch (message.text) { switch (message.text) {
case "FETCH_EVENTS": case "FETCH_EVENTS":
setSpinner(); setSpinner();
//$('div.b').hide(); //$('div.b').hide();
break; break;
case "FETCH_EVENTS_SUCCESS": case "FETCH_EVENTS_SUCCESS":
unsetSpinner(); unsetSpinner();
showEvents(); showEvents();
break; break;
case "FETCH_EVENTS_DATA_ERROR": case "FETCH_EVENTS_DATA_ERROR":
unsetSpinner(); unsetSpinner();
showError("Error in fetching data!! Check your internet connection"); showError("Error in fetching data!! Check your internet connection");
break; break;
case "FETCH_EVENTS_URL_ERROR": case "FETCH_EVENTS_URL_ERROR":
unsetSpinner(); unsetSpinner();
showError("Configure ip address,API password, user name and password with correct values"); showError(
break; "Configure ip address,API password, user name and password with correct values"
default: );
console.log("Unrecognized message: ", message.text); break;
break; default:
} console.log("Unrecognized message: ", message.text);
}); break;
}
});
}); });
function setSpinner () { function setSpinner() {
$('#refr_img_id').attr("src", "images/spinny.gif"); $("#refr_img_id").attr("src", "images/spinny.gif");
} }
function unsetSpinner() { function unsetSpinner() {
$('#refr_img_id').attr("src", "images/refresh.png"); $("#refr_img_id").attr("src", "images/refresh.png");
} }
function clearError() { function clearError() {
$('.error').hide(); $(".error").hide();
$('.error a').text(""); $(".error a").text("");
$('.result').css('height', null); $(".result").css("height", null);
} }
function showError(text){ function showError(text) {
$('.error a').text(text); $(".error a").text(text);
$('.error').show(); $(".error").show();
$('.result').height(420); $(".result").height(420);
} }
function showEvents(){ function showEvents() {
clearError();
$("#events").empty();
var e_refr = document.getElementById("event_temp");
if (e_refr) {
wrapper.removeChild(e_refr);
}
var allEvents = bg.fetchEvents();
var notVisitedEvents = bg.fetchNotVisited();
var eve = document.createElement("div");
eve.id = "event_temp";
eve.setAttribute("class", "b");
clearError(); var i = 0;
$('#events').empty(); if (allEvents.length > 0) {
var e_refr = document.getElementById('event_temp'); while (i < max_events && i < allEvents.length) {
if(e_refr){ var eve_title = document.createElement("div");
wrapper.removeChild(e_refr); eve_title.id = "e_" + i + "_" + allEvents[i]["id"];
} var img = document.createElement("img");
var allEvents = bg.fetchEvents(); img.src = "images/plus.png";
var notVisitedEvents = bg.fetchNotVisited(); img.className = "pm";
var eve=document.createElement('div'); img.id = "i_" + i + "_" + allEvents[i]["id"];
eve.id="event_temp"; eve_title.appendChild(img);
eve.setAttribute("class","b"); var div_empty = document.createElement("img");
var a = document.createElement("a");
var i=0; var temp_style;
if(allEvents.length>0){
while(i<max_events && i<allEvents.length){
var eve_title=document.createElement('div');
eve_title.id = 'e_' + i + '_' + allEvents[i]['id'];
var img = document.createElement('img');
img.src = 'images/plus.png';
img.className ='pm';
img.id='i_' + i + '_' + allEvents[i]['id'];
eve_title.appendChild(img);
var div_empty = document.createElement('img');
var a = document.createElement('a');
var temp_style;
var agent_url = (allEvents[i]["agent"] == 0)
? localStorage["ip_address"]
+ "/index.php?sec=eventos&sec2=operation/events/events"
: localStorage["ip_address"]
+ "/index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente="
+ allEvents[i]['agent'];
a.setAttribute("href",agent_url);
a.target = "_blank";
a.className = 'a_2_mo';
a.innerText = allEvents[i]['title'];
eve_title.setAttribute("class","event sev-" + allEvents[i]['severity']);
if (notVisitedEvents[allEvents[i]['id']] === true) { var agent_url =
eve_title.style.fontWeight = 600; allEvents[i]["agent"] == 0
} ? localStorage["ip_address"] +
"/index.php?sec=eventos&sec2=operation/events/events"
eve_title.appendChild(a); : localStorage["ip_address"] +
eve.appendChild(eve_title); "/index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=" +
allEvents[i]["agent"];
var time=allEvents[i]['date'].split(" "); a.setAttribute("href", agent_url);
var time_text = time[0]+" "+time[1]; a.target = "_blank";
a.className = "a_2_mo";
var p = document.createElement('p');
var id = (allEvents[i]['module']==0)
? "."
: " in the module with Id "+ allEvents[i]['module'] + ".";
p.innerText = allEvents[i]['type']+" : "+allEvents[i]['source']+". Event occured at "+ time_text+id;
p.id = 'p_' + i;
eve_title.appendChild(p);
i++;
}
$('#events').append(eve);
$('img.pm').click(showHide); a.innerText = allEvents[i]["title"];
$('div.b').show(); eve_title.setAttribute("class", "event sev-" + allEvents[i]["severity"]);
} else {
showError("Error in fetching data!! Check your internet connection"); if (notVisitedEvents[allEvents[i]["id"]] === true) {
} eve_title.style.fontWeight = 600;
}
localStorage["new_events"]=0;
bg.updateBadge(); eve_title.appendChild(a);
eve.appendChild(eve_title);
var time = allEvents[i]["date"].split(" ");
var time_text = time[0] + " " + time[1];
var p = document.createElement("p");
var id =
allEvents[i]["module"] == 0
? "."
: " in the module with Id " + allEvents[i]["module"] + ".";
p.innerText =
allEvents[i]["type"] +
" : " +
allEvents[i]["source"] +
". Event occured at " +
time_text +
id;
p.id = "p_" + i;
eve_title.appendChild(p);
i++;
}
$("#events").append(eve);
$("img.pm").click(showHide);
$("div.b").show();
} else {
showError("No events");
}
localStorage["new_events"] = 0;
bg.updateBadge();
} }
function showHide() { function showHide() {
var id = $(this).attr('id'); var id = $(this).attr("id");
// Image id has the form i_<position>_<eventId> // Image id has the form i_<position>_<eventId>
var nums = id.split('_'); var nums = id.split("_");
var pid = "p_" + nums[1]; var pid = "p_" + nums[1];
// Mark as visited if visited // Mark as visited if visited
if($(this).parent().css('font-weight') == '600') { if (
bg.removeNotVisited(nums[2]); $(this)
$(this).parent().css('font-weight', ''); .parent()
} .css("font-weight") == "600"
) {
bg.removeNotVisited(nums[2]);
$(this)
.parent()
.css("font-weight", "");
}
// Toggle information // Toggle information
if($('#' + pid).css('display') == 'none') { if ($("#" + pid).css("display") == "none") {
$('#' + pid).slideDown(); $("#" + pid).slideDown();
$(this).attr({src: 'images/minus.png'}); $(this).attr({ src: "images/minus.png" });
} } else {
else { $("#" + pid).slideUp();
$('#' + pid).slideUp(); $(this).attr({ src: "images/plus.png" });
$(this).attr({src: 'images/plus.png'}); }
}
} }
function mrefresh(){ function mrefresh() {
localStorage["new_events"]=0; localStorage["new_events"] = 0;
bg.updateBadge(); bg.updateBadge();
clearError(); clearError();
bg.resetInterval(); bg.resetInterval();
bg.main(); bg.main();
} }

View File

@ -1,30 +1,30 @@
{ {
"name": "__MSG_name__", "name": "__MSG_name__",
"version": "2.1", "version": "2.2",
"manifest_version": 2, "manifest_version": 2,
"description": "Pandora FMS Event viewer Chrome extension", "description": "Pandora FMS Event viewer Chrome extension",
"homepage_url": "http://pandorafms.com", "homepage_url": "http://pandorafms.com",
"browser_action": { "browser_action": {
"default_title": "__MSG_default_title__", "default_title": "__MSG_default_title__",
"default_icon": "images/icon.png", "default_icon": "images/icon.png",
"default_popup": "popup.html" "default_popup": "popup.html"
}, },
"background": { "background": {
"page": "background.html" "page": "background.html"
}, },
"icons": { "icons": {
"128": "images/icon128.png", "128": "images/icon128.png",
"16": "images/icon16.png", "16": "images/icon16.png",
"32": "images/icon32.png", "32": "images/icon32.png",
"48": "images/icon48.png" "48": "images/icon48.png"
}, },
"options_page": "options.html", "options_page": "options.html",
"permissions": [ "permissions": [
"tabs", "tabs",
"notifications", "notifications",
"http://*/*", "http://*/*",
"https://*/*", "https://*/*",
"background" "background"
], ],
"default_locale": "en" "default_locale": "en"
} }