Merge branch 'ent-1624-extension-chrome-de-eventos-desactualizada' into 'develop'

Ent 1624 extension chrome de eventos desactualizada

See merge request artica/pandorafms!1152
This commit is contained in:
vgilc 2018-01-29 12:50:19 +01:00
commit 98dc8f0fa5
23 changed files with 604 additions and 424 deletions

View File

@ -1,84 +1,170 @@
* {
font-family: "Open Sans", "Noto Sans", sans-serif
}
body { body {
min-width:425px; min-width: 425px;
min-height:540px; min-height: 540px;
margin:5px; margin: 5px;
font-family:Tahoma, Geneva, Arial; font-family: Tahoma, Geneva, Arial;
font-size:10pt; font-size: 10pt;
} }
h1 { font-weight: bold; font-size:16px; margin:2px 0px 2px 0px; color:#237948; font-family:arial } h1 {
h2{ font-weight: bold;
color : black; font-size: 14px;
margin: 2px 0px 2px 0px;
} }
p h2 {
{ color : #333;
font-family:"Times New Roman"; }
font-size:20px; p {
font-size: 20px;
}
a {
color: #254533;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:visited {
color: #254533; text-decoration:none;
}
a:visited:hover {
text-decoration: underline;
} }
a { color: #254533; text-decoration:none; } span.res {
a:hover { text-decoration:underline; } font-size: 80%;
a:visited { color: #254533; text-decoration:none; } color: #555;
a:visited:hover { text-decoration:underline; } }
span.res { font-size:80%; color:#555; } img.pm {
margin-right: 3px;
img.pm { margin-right:3px;cursor:pointer; margin-top:0px; } cursor: pointer;
div.main{ margin-top: 2px;
background-color : white; float: right;
}
div.main {
background-color: white;
height: 500px; height: 500px;
width: 400px; width: 400px;
} }
div.textarea{ div.textarea {
background-color : #D5DED5; background-color: #D5DED5;
width :100% width: 100%
}
div.e {
text-align: right;
font-size:8pt;
}
div.b {
background-color:white;
display: none;
}
div.b p a {
font-size: 10pt;
} }
div.e{ text-align:right; font-size:8pt; }
div.b { background-color:white; border:1px solid #BABABA; margin:5px; padding:4px; display:none; }
div.b p a { font-size: 10pt; }
div.b p { margin:2px 0px 4px 0px; display:none; color:#333; font-size:9pt; }
div.b div.items p { div.b div.items p {
margin:2px 0px 8px 0px; color:#333; width:355px;float:left;display:block; margin: 2px 0px 8px 0px;
width: 355px;
float: left;
display: block;
} }
div.b div.items p img { div.b div.items p img {
float:left;margin:0px 3px 0px 0px; float: left;
margin: 0px 3px 0px 0px;
} }
div.options_header{ div.options_header {
margin : 10px 10px; margin: 10px 10px;
} }
div.options_divider{ div.options_divider {
width : 100%; width: 627px;
background-color : #C8C8C8; margin-top: 30px;
} }
div.optionsG_textarea{ div.options_divider h2{
background-color : green; margin: 20px 20px 0;
width : 450px; padding: 5px;
margin : 5px, 10px; font-weight: 500;
border: 2px solid #82b92e;
border-top-left-radius: 2px;
border-top-right-radius: 2px;
color: white;
text-align: center;
background: #82b92e;
font-size: 14px;
font-weight: 600;
} }
div.options_textarea{
background-color : #ebebeb; div.options_textarea {
width : 550px; background-color: #f6f6f6;
margin : 10px 10px; width: 550px;
margin: 0 20px;
padding: 10px 10px 25px 25px;
border-bottom-left-radius: 2px;
border-bottom-right-radius: 2px;
border: 1px solid #e4e4e4;
border-top: 0;
}
div.options_footer {
width: 550px;
margin: 10px 10px;
padding: 10px; padding: 10px;
-webkit-border-radius:10px;
border: 2px solid #c8c8c8;
} }
div.options_footer{ select {
width : 550px; background: white;
margin : 10px 10px; border: 1px solid #888;
padding: 10px; font-size: smaller;
padding: 2px 1px;
width: 250px;
}
.sound_selector td:first-child {
padding-left: 25px;
width: 39%;
}
.options_textarea button {
background-color: #82b92e;
border: 1px solid #82b92e;
color: white;
padding: 6px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 12px;
border-radius: 2px;
margin: 25px 0px 0px 422px;
}
.options_textarea button:hover {
background-color: transparent;
color: #82b92e;
cursor: pointer;
}
.options_textarea h3 {
text-align: left;
font-size: 11.4pt;
}
button h3 {
margin: 0;
font-size: 10pt !important;
} }
.tooltip { .tooltip {
display:none; display: none;
font-size:12px; font-size: 12px;
height:70px; height: 70px;
width:160px; width: 160px;
padding:25px; padding: 25px;
color:#eee; color: #eee;
} }
.spinner { .spinner {
@ -87,11 +173,78 @@ div.options_footer{
left: 50%; left: 50%;
margin-left: -50px; margin-left: -50px;
margin-top: -50px; margin-top: -50px;
text-align:center; text-align: center;
z-index:1234; z-index: 1234;
overflow: auto; overflow: auto;
width: 100px; width: 100px;
height: 102px; height: 102px;
} }
.error {
display: flex;
border: solid #e4e4e4 1px;
border-radius: 2px;
background: #f6f6f6;
padding: 10px;
margin: 10px;
margin-top: 35px;
}
.error_text {
margin: 0 10px;
}
.result {
margin: 10px;
height: 500;
overflow-y: auto;
}
#events_title {
padding: 5px 0;
margin: 0;
padding-bottom: 10px;
border-bottom: 1px solid #e5e5e5;
}
.event {
border: solid 1px #e5e5e5;
border-top: 0;
padding: 5px 6px;
color: white;
}
.event a {
margin-left: 5px;
color: white;
font-size: 9pt;
}
.sev-Warning a {
margin-left: 5px;
color: #333;
}
.event p {
margin: 0 0 0 6px;
padding-top: 2px;
display: none;
font-size: 8pt;
}
.sev-Warning {
background: #FDDD30;
color: #333;
}
.sev-Critical {
background: #F84348;
}
.sev-Informational {
background: #4CA8E0;
}
.sev-Normal {
background: #84B839;
}
.sev-Maintenance {
background: #A8A8A8;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 507 B

After

Width:  |  Height:  |  Size: 468 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 839 B

After

Width:  |  Height:  |  Size: 636 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 703 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 91 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 501 B

After

Width:  |  Height:  |  Size: 428 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@ -1,29 +1,35 @@
var timer = null; var refreshTimer = null;
var allEvents=new Array(); var isFetching = null;
var newEvents=new Array(); var storedEvents = new Array();
var oldEvents=new Array(); var notVisited = {};
var api_div_numbers=21;
$(window).load(function() { $(window).load(function() {
initilise(); initilise();
if(timer) { // Wait some ms to throw main function
clearTimeout(timer); var delay = setTimeout(main, 100);
} resetInterval();
timer =setTimeout(main , 100 );
}); });
function fetchEvents() {
return storedEvents;
function fetchEvents(){
return oldEvents;
} }
function fetchNotVisited() {
return notVisited;
}
function removeNotVisited(eventId) {
if (notVisited[eventId] === true) delete notVisited[eventId];
}
function main() { function main() {
var url=localStorage["ip_address"]+'/include/api.php?op=get&op2=events&return_type=csv&apipass='+localStorage["api_pass"]+'&user='+localStorage["user_name"]+'&pass='+localStorage["pass"];
var feedUrl = url; chrome.runtime.sendMessage({text: "FETCH_EVENTS"});
localStorage["data_check"]="true"; // Do not fetch if is fetching now
if (isFetching) return;
isFetching = true;
var feedUrl = localStorage["ip_address"]+'/include/api.php?op=get&op2=events&return_type=csv&apipass='+localStorage["api_pass"]+'&user='+localStorage["user_name"]+'&pass='+localStorage["pass"];
req = new XMLHttpRequest(); req = new XMLHttpRequest();
req.onload = handleResponse; req.onload = handleResponse;
req.onerror = handleError; req.onerror = handleError;
@ -32,96 +38,85 @@ function main() {
} }
function handleError() { function handleError() {
localStorage["data_check"]="false"; chrome.runtime.sendMessage({text: "FETCH_EVENTS_URL_ERROR"});
if(timer) { isFetching = false;
clearTimeout(timer);
}
timer =setTimeout(main , 1000);
} }
function handleResponse() { function handleResponse() {
var doc = req.responseText; var doc = req.responseText;
if (doc=="auth error") { if (doc=="auth error") {
localStorage["data_check"]="false"; chrome.runtime.sendMessage({text: "FETCH_EVENTS_URL_ERROR"});
if(timer) { } else {
clearTimeout(timer); var n = doc.search("404 Not Found");
} if (n>0) {
timer =setTimeout(main , 1000); chrome.runtime.sendMessage({text: "FETCH_EVENTS_DATA_ERROR"});
} } else {
else{
var n=doc.search("404 Not Found");
if(n>0){
localStorage["data_check"]="false";
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(main , 1000);
}
else{
localStorage["data_check"]="true"
getEvents(doc); getEvents(doc);
chrome.runtime.sendMessage({text: "FETCH_EVENTS_SUCCESS"});
} }
} }
isFetching = false;
} }
function getEvents(reply){ function getEvents(reply){
if(check()){ var fetchedEvents = parseReplyEvents(reply);
all_event_array=reply.split("\n");
allEvents=divideArray(all_event_array); // If there is no events requested, mark all as visited
if(oldEvents.length==0){ if (storedEvents.length == 0) {
oldEvents=allEvents; notVisited = {};
storedEvents = fetchedEvents;
return;
}
// Discriminate the new events
newEvents=fetchNewEvents(fetchedEvents,storedEvents);
var newNotVisited = {};
var notVisitedCount = 0;
// Check if popup is displayed to make some actions
var views = chrome.extension.getViews({ type: "popup" });
for(var k=0;k<newEvents.length;k++){
newNotVisited[newEvents[k]['id']] = true;
if (views.length == 0) {
notVisitedCount++;
displayNotification (newEvents[k])
alertsSound(newEvents[k]);
} }
newEvents=fetchNewEvents(allEvents,oldEvents); }
if(newEvents.length!=0){
for(var k=0;k<newEvents.length;k++){ // Make that the old events marked as not visited remains with the
localStorage["new_events"]++; // same status
showNotification(k); for(var k=0;k<fetchedEvents.length;k++){
} if (notVisited[fetchedEvents[k]['id']] === true) {
newNotVisited[fetchedEvents[k]['id']] = true;
notVisitedCount++;
} }
oldEvents=allEvents; }
if(localStorage["new_events"]!=0){ notVisited = newNotVisited;
showBadge(localStorage["new_events"]);
} // Update the number
else{ localStorage["new_events"] = (views.length == 0) ? notVisitedCount : 0;
hideBadge(); updateBadge();
}
// Store the requested events
storedEvents = fetchedEvents;
if(timer) { }
clearTimeout(timer);
} function updateBadge() {
timer =setTimeout(main , localStorage["refresh"]*1000 ); if (localStorage["new_events"] != 0) {
chrome.browserAction.setBadgeBackgroundColor({color:[0,200,0,255]});
chrome.browserAction.setBadgeText({ text: localStorage["new_events"] });
} else {
chrome.browserAction.setBadgeText({ text: "" });
} }
} }
function showBadge(txt) {
chrome.browserAction.setBadgeBackgroundColor({color:[0,200,0,255]});
chrome.browserAction.setBadgeText({ text: txt });
}
function hideBadge() {
chrome.browserAction.setBadgeText({ text: "" });
}
function divideArray(e_array){
var Events=new Array();
for(var i=0;i<e_array.length;i++){
var event=e_array[i].split(";");
Events.push(event);
}
return Events;
}
function hideNotification(){
}
function fetchNewEvents(A,B){ function fetchNewEvents(A,B){
var arrDiff = new Array(); var arrDiff = new Array();
for(var i = 0; i < A.length; i++) { for(var i = 0; i < A.length; i++) {
var id = false; var id = false;
for(var j = 0; j < B.length; j++) { for(var j = 0; j < B.length; j++) {
if(A[i][0] == B[j][0]) { if(A[i]['id'] == B[j]['id']) {
id = true; id = true;
break; break;
} }
@ -134,115 +129,183 @@ function fetchNewEvents(A,B){
} }
function showNotification(eventId){ function parseReplyEvents (reply) {
var Severity;
if(localStorage["sound_alert"]=="on"){ // Split the API response
if(newEvents[eventId][19]=="Critical"){ var e_array = reply.split("\n");
// Form a properly object
var fetchedEvents=new Array();
for(var i=0;i<e_array.length;i++){
// Avoid to parse empty lines
if (e_array[i].length == 0) continue;
var event=e_array[i].split(";");
fetchedEvents.push({
'id' : event[0],
'agent_name' : event[1],
'agent' : event[2],
'date' : event[5],
'title' : event[6],
'module' : event[9],
'type' : event[14],
'source' : event[17],
'severity' : event[28],
'visited' : false
});
}
// Return the events
return fetchedEvents;
}
function alertsSound(pEvent){
if(localStorage["sound_alert"]!="on"){
return;
}
switch (pEvent['severity']) {
case "Critical":
playSound(localStorage["critical"]); playSound(localStorage["critical"]);
} break;
if(newEvents[eventId][19]=="Informational"){ case "Informational":
playSound(localStorage["informational"]); playSound(localStorage["informational"]);
} break;
if(newEvents[eventId][19]=="Maintenance"){ case "Maintenance":
playSound(localStorage["maintenance"]); playSound(localStorage["maintenance"]);
} break;
if(newEvents[eventId][19]=="Normal"){ case "Normal":
playSound(localStorage["normal"]); playSound(localStorage["normal"]);
} break;
if(newEvents[eventId][19]=="Warning"){ case "Warning":
playSound(localStorage["warning"]); playSound(localStorage["warning"]);
} break;
} }
var notification = webkitNotifications.createHTMLNotification(
"notification.html?event="+eventId
);
notification.show();
} }
function getNotification(eventId){ function displayNotification (pEvent) {
var title=newEvents[eventId][6];
var id; // Check if the user is okay to get some notification
if(newEvents[eventId][9]==0){ if (Notification.permission === "granted") {
id="."; // If it's okay create a notification
getNotification(pEvent);
} }
else {
id= " in the module with Id "+ newEvents[eventId][9] + ".";
}
var event = newEvents[eventId][14]+" : "+newEvents[eventId][17]+". Event occured at "+ newEvents[eventId][5]+id;
return '<a>' + title + '</a> <br/> <span style="font-size:80%">' + event + '</span>';
// Otherwise, we need to ask the user for permission
// Note, Chrome does not implement the permission static property
// So we have to check for NOT 'denied' instead of 'default'
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// Whatever the user answers, we make sure we store the information
if(!('permission' in Notification)) {
Notification.permission = permission;
}
// If the user is okay, let's create a notification
if (permission === "granted") getNotification(pEvent);
});
}
} }
function check(){ function getNotification(pEvent){
if (localStorage["data_check"]=="true" && localStorage["ip_address"] != null && localStorage["api_pass"] != null &&localStorage["user_name"]!=null &&localStorage["pass"]!=null && localStorage["ip_address"] != "" && localStorage["api_pass"] != "" &&localStorage["user_name"]!="" &&localStorage["pass"]!=""){
return true; // Build the event text
var even = pEvent['type'];
if (pEvent['source'] != '') even += " : " + pEvent['source'];
even += ". Event occured at " + pEvent['date'];
if(pEvent['module'] != 0) even += " in the module with Id "+ pEvent['module'];
even += ".";
var url = (pEvent['agent']=="")
? 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=" + pEvent['agent'];
var notification = new Notification(
pEvent['title'],
{
body: even,
icon: "images/icon.png"
}
);
// Add the link
notification.onclick = function (event) {
event.preventDefault();
window.open(url, '_blank');
} }
else
return false; // Close notification after 10 secs
setTimeout(function() {notification.close()}, 10000);
}
function resetInterval () {
if (refreshTimer) clearInterval(refreshTimer);
refreshTimer = setInterval(main, localStorage["refresh"]*1000);
} }
function initilise(){ function initilise(){
if(localStorage["ip_address"]==undefined){ if (isFetching == null) isFetching = false;
localStorage["ip_address"]="http://firefly.artica.es/pandora_demo"; if(localStorage["ip_address"]==undefined){
localStorage["ip_address"]="http://firefly.artica.es/pandora_demo";
} }
if(localStorage["api_pass"]==undefined){ if(localStorage["api_pass"]==undefined){
localStorage["api_pass"]="doreik0"; localStorage["api_pass"]="doreik0";
} }
if(localStorage["user_name"]==undefined){ if(localStorage["user_name"]==undefined){
localStorage["user_name"]="demo"; localStorage["user_name"]="demo";
} }
if(localStorage["pass"]==undefined){ if(localStorage["pass"]==undefined){
localStorage["pass"]="demo"; localStorage["pass"]="demo";
} }
if(localStorage["critical"]==null){ if(localStorage["critical"]==null){
localStorage["critical"]="11"; localStorage["critical"]="11";
} }
if(localStorage["informational"]==null){ if(localStorage["informational"]==null){
localStorage["informational"]="1"; localStorage["informational"]="1";
} }
if(localStorage["maintenance"]==null){ if(localStorage["maintenance"]==null){
localStorage["maintenance"]="10"; localStorage["maintenance"]="10";
} }
if(localStorage["normal"]==null){ if(localStorage["normal"]==null){
localStorage["normal"]="6"; localStorage["normal"]="6";
} }
if(localStorage["warning"]==null){ if(localStorage["warning"]==null){
localStorage["warning"]="2"; localStorage["warning"]="2";
} }
if(localStorage["events"]==null){ if(localStorage["events"]==null){
localStorage["events"]=20; localStorage["events"]=20;
} }
if(localStorage["refresh"]==null){ if(localStorage["refresh"]==null){
localStorage["refresh"]="10"; localStorage["refresh"]="10";
} }
if(localStorage["ip_address"]==null){ if(localStorage["ip_address"]==null){
localStorage["ip_address"]="http://firefly.artica.es/pandora_demo"; localStorage["ip_address"]="http://firefly.artica.es/pandora_demo";
} }
if(localStorage["api_pass"]==null){ if(localStorage["api_pass"]==null){
localStorage["api_pass"]="doreik0"; localStorage["api_pass"]="doreik0";
} }
if(localStorage["user_name"]==null){ if(localStorage["user_name"]==null){
localStorage["user_name"]="demo"; localStorage["user_name"]="demo";
} }
if(localStorage["pass"]==null){ if(localStorage["pass"]==null){
localStorage["pass"]="demo"; localStorage["pass"]="demo";
} }
if(localStorage["sound_alert"]==null){ if(localStorage["sound_alert"]==null){
localStorage["sound_alert"]="on"; localStorage["sound_alert"]="on";
} }
if(localStorage["changed"]==null){ if(localStorage["changed"]==null){
localStorage["changed"]="false"; localStorage["changed"]="false";
} }
if(localStorage["new_events"]==null){ if(localStorage["new_events"]==null){
localStorage["new_events"]=parseInt(localStorage["events"]); localStorage["new_events"]=parseInt(localStorage["events"]);
} }
if(localStorage["error"]==null) {
localStorage["error"] = true;
}
} }

View File

@ -11,7 +11,7 @@ function initialise(){
document.getElementById('normal').value = localStorage["normal"]; document.getElementById('normal').value = localStorage["normal"];
document.getElementById('warning').value = localStorage["warning"]; document.getElementById('warning').value = localStorage["warning"];
document.getElementById('refresh').value = localStorage["refresh"]; document.getElementById('refresh').value = localStorage["refresh"];
document.getElementById('events').value = localStorage["events"]; document.getElementById('number_events').value = localStorage["events"];
if(localStorage["sound_alert"]=="on"){ if(localStorage["sound_alert"]=="on"){
disable(false); disable(false);
document.getElementById('sound_alert_o').checked=true; document.getElementById('sound_alert_o').checked=true;
@ -20,7 +20,6 @@ function initialise(){
disable(true); disable(true);
document.getElementById('sound_alert_f').checked=true; document.getElementById('sound_alert_f').checked=true;
} }
} }
function change(value, id){ function change(value, id){
@ -46,16 +45,13 @@ function change_o(value, id){
if(id=="refresh"){ if(id=="refresh"){
localStorage["refresh"]=value; localStorage["refresh"]=value;
} }
if(id=="events"){ if(id=="number_events"){
localStorage["events"]=value; localStorage["events"]=value;
} }
} }
function change_global(value,id){ function change_global(value,id){
console.log("value => "+value);
console.log("id => "+id);
bg=chrome.extension.getBackgroundPage(); bg=chrome.extension.getBackgroundPage();
bg.location.reload();
if(id=="ip_address"){ if(id=="ip_address"){
localStorage["ip_address"]=value; localStorage["ip_address"]=value;
} }
@ -96,12 +92,6 @@ function disable(state){
} }
} }
function windowClose() {
//window.close();
console.log("close");
}
//Add callbacks to elements //Add callbacks to elements
$(document).ready (function () { $(document).ready (function () {
@ -163,13 +153,12 @@ $(document).ready (function () {
change_o($(this).val(), "refresh"); change_o($(this).val(), "refresh");
}); });
$("#events").change(function () { $("#number_events").change(function () {
change_o($(this).val(), "events"); change_o($(this).val(), "number_events");
}); });
//Close button //Close button
$("#close").click (function () { $("#close").click (function () {
window.close(); window.close();
}); });
}); });

View File

@ -1,5 +1,3 @@
var timer = null;
var event_array;
var max_events; var max_events;
var bg; var bg;
$(document).ready(function(){ $(document).ready(function(){
@ -8,198 +6,165 @@ $(document).ready(function(){
localStorage["events"]="20"; localStorage["events"]="20";
} }
bg=chrome.extension.getBackgroundPage(); bg=chrome.extension.getBackgroundPage();
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(mainPoP , 2000 );
});
function mainPoP(){ // Display the information
if(bg.check()){ if (bg.fetchEvents().length == 0) {
showError("Error in fetching data!! Check your internet connection");
} else {
showEvents(); showEvents();
} }
else
{ // Adding buttons listeners
showUrlError(); document.getElementById("m_refresh").addEventListener("click", mrefresh);
}
} // Added listener to background messages
function showUrlError(){ chrome.runtime.onMessage.addListener(function(message,sender,sendResponse){
var res=document.createDocumentFragment(); switch (message.text) {
var r = document.getElementById('e'); case "FETCH_EVENTS":
var eve=document.createElement('div'); setSpinner();
eve.id="event_temp"; //$('div.b').hide();
eve.setAttribute("class","b"); break;
case "FETCH_EVENTS_SUCCESS":
var p = document.createElement('a'); unsetSpinner();
p.href="options.html"; showEvents();
p.target="_blank"; break;
p.innerText="Configure ip address,API password, user name and password with correct values"; case "FETCH_EVENTS_DATA_ERROR":
eve.appendChild(p); unsetSpinner();
res.appendChild(eve); showError("Error in fetching data!! Check your internet connection");
r.parentNode.insertBefore(res,r); break;
$('.loader').hide(); case "FETCH_EVENTS_URL_ERROR":
$('div.b').show(); unsetSpinner();
showError("Configure ip address,API password, user name and password with correct values");
if(timer) { break;
clearTimeout(timer); default:
} console.log("Unrecognized message: ", message.text);
timer =setTimeout(refresh , 1000 ); break;
}
});
});
function setSpinner () {
$('#refr_img_id').attr("src", "images/spinny.gif");
} }
function showDataError(){ function unsetSpinner() {
var res=document.createDocumentFragment(); $('#refr_img_id').attr("src", "images/refresh.png");
var r = document.getElementById('e'); }
var eve=document.createElement('div');
eve.id="event_temp"; function clearError() {
eve.setAttribute("class","b"); $('.error').hide();
$('.error a').text("");
var p = document.createElement('a'); $('.result').css('height', null);
p.innerText="Error in fetching data!! Check your internet connection"; }
eve.appendChild(p);
res.appendChild(eve); function showError(text){
r.parentNode.insertBefore(res,r); $('.error a').text(text);
$('.loader').hide(); $('.error').show();
$('div.b').show(); $('.result').height(420);
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(refresh , 1000 );
} }
function showEvents(){ function showEvents(){
var allEvents=bg.fetchEvents();
var r = document.getElementById('e'); clearError();
var res=document.createDocumentFragment(); $('#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'); var eve=document.createElement('div');
eve.id="event_temp"; eve.id="event_temp";
eve.setAttribute("class","b"); eve.setAttribute("class","b");
var i=0; var i=0;
if(allEvents.length>0){ if(allEvents.length>0){
while(i<max_events){ while(i<max_events && i<allEvents.length){
var eve_title=document.createElement('div'); var eve_title=document.createElement('div');
eve_title.id = 'e_' + i + '_' + allEvents[i]['id'];
var img = document.createElement('img'); var img = document.createElement('img');
img.src = 'images/plus.gif'; img.src = 'images/plus.png';
img.width = '9';
img.height='9';
img.className ='pm'; img.className ='pm';
img.id='i_' + i; img.id='i_' + i + '_' + allEvents[i]['id'];
eve_title.appendChild(img); eve_title.appendChild(img);
var div_empty = document.createElement('img');
var a = document.createElement('a'); var a = document.createElement('a');
var temp_style; var temp_style;
var agent_url; var agent_url = (allEvents[i]["agent_name"] == 0)
if(allEvents[i][1]==""){; ? localStorage["ip_address"]
agent_url=localStorage["ip_address"]+"/index.php?sec=eventos&sec2=operation/events/events" ; + "/index.php?sec=eventos&sec2=operation/events/events"
}else{ : localStorage["ip_address"]
agent_url=localStorage["ip_address"]+"/index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente="+allEvents[i][1]; + "/index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente="
} + allEvents[i]['agent_name'];
a.setAttribute("href",agent_url); a.setAttribute("href",agent_url);
a.target="_blank"; a.target = "_blank";
a.className = 'a_2_mo';
a.innerText = allEvents[i][6]; a.innerText = allEvents[i]['title'];
eve_title.setAttribute("class","event sev-" + allEvents[i]['severity']);
if(i<localStorage["new_events"]){
var temp_style="font-weight:bold;"; if (notVisitedEvents[allEvents[i]['id']] === true) {
} eve_title.style.fontWeight = 600;
else{
var temp_style="font-weight:normal;";
} }
if(allEvents[i][19]=="Warning"){
eve_title.setAttribute("style","background:#FCED7E; margin-bottom:-12px;"+temp_style);
}
if(allEvents[i][19]=="Critical"){
eve_title.setAttribute("style","background:#FA7A7A; margin-bottom:-12px;"+temp_style);
}
if(allEvents[i][19]=="Informational"){
eve_title.setAttribute("style","background:#7FB9FA; margin-bottom:-12px;"+temp_style);
}
if(allEvents[i][19]=="Normal"){
eve_title.setAttribute("style","background:#A8D96C; margin-bottom:-12px;"+temp_style);
}
if(allEvents[i][19]=="Maintenance"){
eve_title.setAttribute("style","background:#BABDB6; margin-bottom:-12px;"+temp_style);
}
eve_title.appendChild(a); eve_title.appendChild(a);
eve.appendChild(eve_title); eve.appendChild(eve_title);
var b = document.createElement('br');
eve.appendChild(b);
var time=allEvents[i][5].split(" "); var time=allEvents[i]['date'].split(" ");
var time_text = time[0]+" "+time[1]; var time_text = time[0]+" "+time[1];
var p = document.createElement('p'); var p = document.createElement('p');
var id; var id = (allEvents[i]['module']==0)
if(allEvents[i][9]==0){ ? "."
id="."; : " in the module with Id "+ allEvents[i]['module'] + ".";
}
else {
id= " in the module with Id "+ allEvents[i][9] + ".";
}
p.innerText = allEvents[i][14]+" : "+allEvents[i][17]+". Event occured at "+ time_text+id; p.innerText = allEvents[i]['type']+" : "+allEvents[i]['source']+". Event occured at "+ time_text+id;
p.id = 'p_' + i; p.id = 'p_' + i;
eve.appendChild(p); eve_title.appendChild(p);
i++; i++;
} }
res.appendChild(eve); $('#events').append(eve);
r.parentNode.insertBefore(res,r);
$('img.pm').click(showHide); $('img.pm').click(showHide);
$('.loader').hide();
$('div.b').show(); $('div.b').show();
} } else {
else{ showError("Error in fetching data!! Check your internet connection");
showDataError();
} }
localStorage["new_events"]=0; localStorage["new_events"]=0;
bg.hideBadge(); bg.updateBadge();
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(refresh , 30*1000 );
} }
function showHide() { function showHide() {
var id = $(this).attr('id'); var id = $(this).attr('id');
var num = id.split("_")[1]; // Image id has the form i_<position>_<eventId>
var pid = "p_" + num; 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', '');
}
// Toggle information
if($('#' + pid).css('display') == 'none') { if($('#' + pid).css('display') == 'none') {
$('#' + pid).slideDown("fast"); $('#' + pid).slideDown();
$(this).attr({src: 'images/minus.gif'}); $(this).attr({src: 'images/minus.png'});
} }
else { else {
$('#' + pid).slideUp("fast"); $('#' + pid).slideUp();
$(this).attr({src: 'images/plus.gif'}); $(this).attr({src: 'images/plus.png'});
} }
} }
function refresh(){
localStorage["new_events"]=0;
bg.hideBadge();
var e = document.getElementById('event_temp');
if(e){
e.parentNode.removeChild(e);
}
mainPoP();
}
function mrefresh(){ function mrefresh(){
localStorage["new_events"]=0; localStorage["new_events"]=0;
bg.hideBadge(); bg.updateBadge();
var bg=chrome.extension.getBackgroundPage(); clearError();
bg.location.reload(); bg.resetInterval();
var e = document.getElementById('event_temp'); bg.main();
if(e){
e.parentNode.removeChild(e);
}
mainPoP();
} }

View File

@ -20,10 +20,10 @@
}, },
"options_page": "options.html", "options_page": "options.html",
"permissions": [ "permissions": [
"tabs", "tabs",
"notifications", "notifications",
"http://*/*", "http://*/*",
"background" "background"
], ],
"default_locale": "en" "default_locale": "en"
} }

View File

@ -3,6 +3,7 @@
<head> <head>
<title>Pandora FMS extension</title> <title>Pandora FMS extension</title>
<link rel="stylesheet" href="css/popup.css" type="text/css" /> <link rel="stylesheet" href="css/popup.css" type="text/css" />
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,500,600' rel='stylesheet' type='text/css'>
<script src="js/jquery-1.7.2.min.js"></script> <script src="js/jquery-1.7.2.min.js"></script>
<script src="js/sound.js"></script> <script src="js/sound.js"></script>
<script src="js/options.js"></script> <script src="js/options.js"></script>
@ -35,23 +36,18 @@
<td> <input type="password" size=50px name="pass" id="pass"> </td> <td> <input type="password" size=50px name="pass" id="pass"> </td>
</tr> </tr>
</table> </table>
</div> <br/>
<div class="options_textarea">
<table width=450px> <table width=450px>
<caption><h3>Event Alert Sounds Configuration</h3></caption> <caption><h3>Event Alert Sounds Configuration</h3></caption>
<tr> <tr>
<td title="All sound alerts of notifications on/off" style="cursor:help">Sound Alerts </td> <td style='padding-bottom: 15px;' title="All sound alerts of notifications on/off" style="cursor:help">Sound Alerts </td>
<td> <td style='padding-bottom: 15px;'>
<input type="radio" id="sound_alert_o" name="sound_alert" value="on" /> On <input type="radio" id="sound_alert_o" name="sound_alert" value="on" /> On
<input type="radio" id="sound_alert_f" name="sound_alert" value="off" /> Off <input type="radio" id="sound_alert_f" name="sound_alert" value="off" /> Off
</td> </td>
</tr> </tr>
<tr> <tr class="sound_selector">
<td><b>Severity</b></td>
<td ><b>Sound Type</b></td>
</tr>
<tr>
<td>Critical</td> <td>Critical</td>
<td> <td>
<select id="critical"> <select id="critical">
@ -69,7 +65,7 @@
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr class="sound_selector">
<td>Informational</td> <td>Informational</td>
<td> <td>
<select id="informational"> <select id="informational">
@ -87,7 +83,7 @@
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr class="sound_selector">
<td>Maintenance</td> <td>Maintenance</td>
<td> <td>
<select id="maintenance"> <select id="maintenance">
@ -105,7 +101,7 @@
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr class="sound_selector">
<td>Normal</td> <td>Normal</td>
<td> <td>
<select id="normal"> <select id="normal">
@ -123,7 +119,7 @@
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr class="sound_selector">
<td>Warning</td> <td>Warning</td>
<td> <td>
<select id="warning"> <select id="warning">
@ -142,8 +138,8 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td title="Automatic Refresh time to fetch new events" style="cursor:help">Auto Refresh Time</td> <td style='padding-top: 15px;' title="Automatic Refresh time to fetch new events" style="cursor:help">Auto Refresh Time</td>
<td> <td style='padding-top: 15px;'>
<select id="refresh"> <select id="refresh">
<option value="5">5 seconds</option> <option value="5">5 seconds</option>
<option value="10">10 seconds</option> <option value="10">10 seconds</option>
@ -161,7 +157,7 @@
<tr> <tr>
<td title="Number of events to be displayed in pop up window" style="cursor:help">Number of events</td> <td title="Number of events to be displayed in pop up window" style="cursor:help">Number of events</td>
<td> <td>
<select id="events"> <select id="number_events">
<option value="5">5</option> <option value="5">5</option>
<option value="10">10</option> <option value="10">10</option>
<option value="12">12</option> <option value="12">12</option>
@ -173,10 +169,11 @@
</td> </td>
</tr> </tr>
</table> </table>
<button id="close" type="button"><h3>Close</h3></button>
</div> </div>
<div class="options_footer"> <div class="options_footer">
<button id="close" type="button"><h3>Close</h3></button> <p style="display: none;font-family:arial;font-style:italic;color:black;font-size:11px;">Author Information : R.Hareesan (rharishan@gmail.com)</p>
<p style="font-family:arial;font-style:italic;color:black;font-size:11px;">Author Information : R.Hareesan (rharishan@gmail.com)</p>
</div> </div>
</body> </body>
</html> </html>

View File

@ -1,5 +1,6 @@
<html> <html>
<head> <head>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/popup.css" type="text/css" /> <link rel="stylesheet" href="css/popup.css" type="text/css" />
<script src="js/jquery-1.7.2.min.js"></script> <script src="js/jquery-1.7.2.min.js"></script>
<script src="js/popup.js"></script> <script src="js/popup.js"></script>
@ -7,16 +8,28 @@
<body> <body>
<div> <div>
<div id="head"> <div id="head">
<a href=""><img src="images/logo.png" border="0"/></a><a href="options.html" target="_blank"><img src="images/gear.png" style='float:right;padding:5px 5px 0 0;border:0px' title="Options"></a> <a href=""><img src="images/logo.png" border="0"/></a>
<a onclick="mrefresh();" style="cursor:pointer" id="m_refresh"><img src="images/refresh.png" style='float:right;padding:5px 5px 0 0;border:0px' title="Refresh"></a> <a href="options.html" target="_blank">
</div> <img src="images/gear.png" style='float:right;padding:5px 5px 0 0;border:0px' title="Options">
</a>
<div class="loader"> <img src='images/spinny.gif'/> Loading... </div> <a style="cursor:pointer" id="m_refresh">
<div class="result" id="result" > <img src="images/refresh.png" id="refr_img_id" style='float:right;padding:5px 5px 0 0;border:0px' title="Refresh">
<div class="b" id="event"> </a>
<h1>Events</h1> </div>
<div class="e" id="e">
<div style="margin-top: 35px">
<div class="error">
<div>
<img src="images/error.png" title="error">
</div>
<div class="error_text">
<h1>ERROR</h1>
<a href="options.html" target="_blank" ></a>
</div>
</div>
<div class="result" id="result">
<div class="b" id="events">
<div class="e" id="e" />
</div> </div>
</div> </div>
</div> </div>