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 bg;
$(document).ready(function(){
max_events=localStorage["events"];
if(localStorage["events"]==undefined){
localStorage["events"]="20";
}
bg=chrome.extension.getBackgroundPage();
$(document).ready(function() {
max_events = localStorage["events"];
if (localStorage["events"] == undefined) {
localStorage["events"] = "20";
}
bg = chrome.extension.getBackgroundPage();
// Display the information
if (bg.fetchEvents().length == 0) {
showError("Error in fetching data!! Check your internet connection");
} else {
showEvents();
}
// Display the information
if (bg.fetchEvents().length == 0) {
showError("No events");
} else {
showEvents();
}
// Adding buttons listeners
document.getElementById("m_refresh").addEventListener("click", mrefresh);
// Adding buttons listeners
document.getElementById("m_refresh").addEventListener("click", mrefresh);
// Added listener to background messages
chrome.runtime.onMessage.addListener(function(message,sender,sendResponse){
switch (message.text) {
case "FETCH_EVENTS":
setSpinner();
//$('div.b').hide();
break;
case "FETCH_EVENTS_SUCCESS":
unsetSpinner();
showEvents();
break;
case "FETCH_EVENTS_DATA_ERROR":
unsetSpinner();
showError("Error in fetching data!! Check your internet connection");
break;
case "FETCH_EVENTS_URL_ERROR":
unsetSpinner();
showError("Configure ip address,API password, user name and password with correct values");
break;
default:
console.log("Unrecognized message: ", message.text);
break;
}
});
// Added listener to background messages
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
switch (message.text) {
case "FETCH_EVENTS":
setSpinner();
//$('div.b').hide();
break;
case "FETCH_EVENTS_SUCCESS":
unsetSpinner();
showEvents();
break;
case "FETCH_EVENTS_DATA_ERROR":
unsetSpinner();
showError("Error in fetching data!! Check your internet connection");
break;
case "FETCH_EVENTS_URL_ERROR":
unsetSpinner();
showError(
"Configure ip address,API password, user name and password with correct values"
);
break;
default:
console.log("Unrecognized message: ", message.text);
break;
}
});
});
function setSpinner () {
$('#refr_img_id').attr("src", "images/spinny.gif");
function setSpinner() {
$("#refr_img_id").attr("src", "images/spinny.gif");
}
function unsetSpinner() {
$('#refr_img_id').attr("src", "images/refresh.png");
$("#refr_img_id").attr("src", "images/refresh.png");
}
function clearError() {
$('.error').hide();
$('.error a').text("");
$('.result').css('height', null);
$(".error").hide();
$(".error a").text("");
$(".result").css("height", null);
}
function showError(text){
$('.error a').text(text);
$('.error').show();
$('.result').height(420);
function showError(text) {
$(".error a").text(text);
$(".error").show();
$(".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();
$('#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");
var i=0;
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']);
var i = 0;
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;
if (notVisitedEvents[allEvents[i]['id']] === true) {
eve_title.style.fontWeight = 600;
}
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);
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";
$('img.pm').click(showHide);
$('div.b').show();
} else {
showError("Error in fetching data!! Check your internet connection");
}
localStorage["new_events"]=0;
bg.updateBadge();
a.innerText = allEvents[i]["title"];
eve_title.setAttribute("class", "event sev-" + allEvents[i]["severity"]);
if (notVisitedEvents[allEvents[i]["id"]] === true) {
eve_title.style.fontWeight = 600;
}
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() {
var id = $(this).attr('id');
// Image id has the form i_<position>_<eventId>
var nums = id.split('_');
var pid = "p_" + nums[1];
var id = $(this).attr("id");
// Image id has the form i_<position>_<eventId>
var nums = id.split("_");
var pid = "p_" + nums[1];
// Mark as visited if visited
if($(this).parent().css('font-weight') == '600') {
bg.removeNotVisited(nums[2]);
$(this).parent().css('font-weight', '');
}
// Mark as visited if visited
if (
$(this)
.parent()
.css("font-weight") == "600"
) {
bg.removeNotVisited(nums[2]);
$(this)
.parent()
.css("font-weight", "");
}
// Toggle information
if($('#' + pid).css('display') == 'none') {
$('#' + pid).slideDown();
$(this).attr({src: 'images/minus.png'});
}
else {
$('#' + pid).slideUp();
$(this).attr({src: 'images/plus.png'});
}
// Toggle information
if ($("#" + pid).css("display") == "none") {
$("#" + pid).slideDown();
$(this).attr({ src: "images/minus.png" });
} else {
$("#" + pid).slideUp();
$(this).attr({ src: "images/plus.png" });
}
}
function mrefresh(){
localStorage["new_events"]=0;
bg.updateBadge();
clearError();
bg.resetInterval();
bg.main();
function mrefresh() {
localStorage["new_events"] = 0;
bg.updateBadge();
clearError();
bg.resetInterval();
bg.main();
}

View File

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