2012-09-11 Dario Rodriguez <dario.rodriguez@artica.es>

* chrome_extension/manifest.json,
	chrome_extension/options.html,
	chrome_extension/background.html,
	chrome_extension/popup.html,
	chrome_extension/css/popup.css,
	chrome_extension/notification.html,
	chrome_extension/js/notification.js,
	chrome_extension/js/options.js,
	chrome_extension/js/background.js,
	chrome_extension/js/popup.js: Fixed extension to
	work with Chrome 2.x



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6954 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
darode 2012-09-11 16:09:43 +00:00
parent 565363255c
commit cfe6055a0c
11 changed files with 701 additions and 603 deletions

View File

@ -1,3 +1,17 @@
2012-09-11 Dario Rodriguez <dario.rodriguez@artica.es>
* chrome_extension/manifest.json,
chrome_extension/options.html,
chrome_extension/background.html,
chrome_extension/popup.html,
chrome_extension/css/popup.css,
chrome_extension/notification.html,
chrome_extension/js/notification.js,
chrome_extension/js/options.js,
chrome_extension/js/background.js,
chrome_extension/js/popup.js: Fixed extension to
work with Chrome 2.x
2012-06-20 Ramon Novoa <rnovoa@artica.es>
* pandora_update_version.sh: Update version in agent configuration

View File

@ -2,256 +2,7 @@
<html>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/sound.js"></script>
<script type="text/javascript">
var timer = null;
var allEvents=new Array();
var newEvents=new Array();
var oldEvents=new Array();
var api_div_numbers=21;
$(window).load(function() {
initilise();
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(main , 100 );
});
function fetchEvents(){
return oldEvents;
}
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;
localStorage["data_check"]="true";
req = new XMLHttpRequest();
req.onload = handleResponse;
req.onerror = handleError;
req.open("GET", feedUrl, true);
req.send(null);
}
function handleError() {
localStorage["data_check"]="false";
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(main , 1000);
}
function handleResponse() {
var doc = req.responseText;
if (doc=="auth error") {
localStorage["data_check"]="false";
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(main , 1000);
}
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);
}
}
}
function getEvents(reply){
if(check()){
all_event_array=reply.split("\n");
allEvents=divideArray(all_event_array);
if(oldEvents.length==0){
oldEvents=allEvents;
}
newEvents=fetchNewEvents(allEvents,oldEvents);
if(newEvents.length!=0){
for(var k=0;k<newEvents.length;k++){
localStorage["new_events"]++;
showNotification(k);
}
}
oldEvents=allEvents;
if(localStorage["new_events"]!=0){
showBadge(localStorage["new_events"]);
}
else{
hideBadge();
}
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(main , localStorage["refresh"]*1000 );
}
}
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){
var arrDiff = new Array();
for(var i = 0; i < A.length; i++) {
var id = false;
for(var j = 0; j < B.length; j++) {
if(A[i][0] == B[j][0]) {
id = true;
break;
}
}
if(!id) {
arrDiff.push(A[i]);
}
}
return arrDiff;
}
function showNotification(eventId){
var Severity;
if(localStorage["sound_alert"]=="on"){
if(newEvents[eventId][19]=="Critical"){
playSound(localStorage["critical"]);
}
if(newEvents[eventId][19]=="Informational"){
playSound(localStorage["informational"]);
}
if(newEvents[eventId][19]=="Maintenance"){
playSound(localStorage["maintenance"]);
}
if(newEvents[eventId][19]=="Normal"){
playSound(localStorage["normal"]);
}
if(newEvents[eventId][19]=="Warning"){
playSound(localStorage["warning"]);
}
}
var notification = webkitNotifications.createHTMLNotification(
"notification.html?event="+eventId
);
notification.show();
}
function getNotification(eventId){
var title=newEvents[eventId][6];
var id;
if(newEvents[eventId][9]==0){
id=".";
}
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>';
}
function check(){
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;
}
else
return false;
}
function initilise(){
if(localStorage["ip_address"]==undefined){
localStorage["ip_address"]="http://firefly.artica.es/pandora_demo";
}
if(localStorage["api_pass"]==undefined){
localStorage["api_pass"]="doreik0";
}
if(localStorage["user_name"]==undefined){
localStorage["user_name"]="demo";
}
if(localStorage["pass"]==undefined){
localStorage["pass"]="demo";
}
if(localStorage["critical"]==null){
localStorage["critical"]="11";
}
if(localStorage["informational"]==null){
localStorage["informational"]="1";
}
if(localStorage["maintenance"]==null){
localStorage["maintenance"]="10";
}
if(localStorage["normal"]==null){
localStorage["normal"]="6";
}
if(localStorage["warning"]==null){
localStorage["warning"]="2";
}
if(localStorage["events"]==null){
localStorage["events"]=20;
}
if(localStorage["refresh"]==null){
localStorage["refresh"]="10";
}
if(localStorage["ip_address"]==null){
localStorage["ip_address"]="http://firefly.artica.es/pandora_demo";
}
if(localStorage["api_pass"]==null){
localStorage["api_pass"]="doreik0";
}
if(localStorage["user_name"]==null){
localStorage["user_name"]="demo";
}
if(localStorage["pass"]==null){
localStorage["pass"]="demo";
}
if(localStorage["sound_alert"]==null){
localStorage["sound_alert"]="on";
}
if(localStorage["changed"]==null){
localStorage["changed"]="false";
}
if(localStorage["new_events"]==null){
localStorage["new_events"]=parseInt(localStorage["events"]);
}
}
</script>
<script src="js/background.js"></script>
<body>
</body>
</html>

View File

@ -58,11 +58,19 @@ div.optionsG_textarea{
margin : 5px, 10px;
}
div.options_textarea{
background-color : #E1EDE5;
width : 450px;
background-color : #ebebeb;
width : 550px;
margin : 10px 10px;
padding: 10px;
-webkit-border-radius:10px;
border: 2px solid #c8c8c8;
}
div.options_footer{
width : 550px;
margin : 10px 10px;
padding: 10px;
}
.tooltip {
display:none;

View File

@ -0,0 +1,248 @@
var timer = null;
var allEvents=new Array();
var newEvents=new Array();
var oldEvents=new Array();
var api_div_numbers=21;
$(window).load(function() {
initilise();
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(main , 100 );
});
function fetchEvents(){
return oldEvents;
}
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;
localStorage["data_check"]="true";
req = new XMLHttpRequest();
req.onload = handleResponse;
req.onerror = handleError;
req.open("GET", feedUrl, true);
req.send(null);
}
function handleError() {
localStorage["data_check"]="false";
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(main , 1000);
}
function handleResponse() {
var doc = req.responseText;
if (doc=="auth error") {
localStorage["data_check"]="false";
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(main , 1000);
}
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);
}
}
}
function getEvents(reply){
if(check()){
all_event_array=reply.split("\n");
allEvents=divideArray(all_event_array);
if(oldEvents.length==0){
oldEvents=allEvents;
}
newEvents=fetchNewEvents(allEvents,oldEvents);
if(newEvents.length!=0){
for(var k=0;k<newEvents.length;k++){
localStorage["new_events"]++;
showNotification(k);
}
}
oldEvents=allEvents;
if(localStorage["new_events"]!=0){
showBadge(localStorage["new_events"]);
}
else{
hideBadge();
}
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(main , localStorage["refresh"]*1000 );
}
}
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){
var arrDiff = new Array();
for(var i = 0; i < A.length; i++) {
var id = false;
for(var j = 0; j < B.length; j++) {
if(A[i][0] == B[j][0]) {
id = true;
break;
}
}
if(!id) {
arrDiff.push(A[i]);
}
}
return arrDiff;
}
function showNotification(eventId){
var Severity;
if(localStorage["sound_alert"]=="on"){
if(newEvents[eventId][19]=="Critical"){
playSound(localStorage["critical"]);
}
if(newEvents[eventId][19]=="Informational"){
playSound(localStorage["informational"]);
}
if(newEvents[eventId][19]=="Maintenance"){
playSound(localStorage["maintenance"]);
}
if(newEvents[eventId][19]=="Normal"){
playSound(localStorage["normal"]);
}
if(newEvents[eventId][19]=="Warning"){
playSound(localStorage["warning"]);
}
}
var notification = webkitNotifications.createHTMLNotification(
"notification.html?event="+eventId
);
notification.show();
}
function getNotification(eventId){
var title=newEvents[eventId][6];
var id;
if(newEvents[eventId][9]==0){
id=".";
}
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>';
}
function check(){
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;
}
else
return false;
}
function initilise(){
if(localStorage["ip_address"]==undefined){
localStorage["ip_address"]="http://firefly.artica.es/pandora_demo";
}
if(localStorage["api_pass"]==undefined){
localStorage["api_pass"]="doreik0";
}
if(localStorage["user_name"]==undefined){
localStorage["user_name"]="demo";
}
if(localStorage["pass"]==undefined){
localStorage["pass"]="demo";
}
if(localStorage["critical"]==null){
localStorage["critical"]="11";
}
if(localStorage["informational"]==null){
localStorage["informational"]="1";
}
if(localStorage["maintenance"]==null){
localStorage["maintenance"]="10";
}
if(localStorage["normal"]==null){
localStorage["normal"]="6";
}
if(localStorage["warning"]==null){
localStorage["warning"]="2";
}
if(localStorage["events"]==null){
localStorage["events"]=20;
}
if(localStorage["refresh"]==null){
localStorage["refresh"]="10";
}
if(localStorage["ip_address"]==null){
localStorage["ip_address"]="http://firefly.artica.es/pandora_demo";
}
if(localStorage["api_pass"]==null){
localStorage["api_pass"]="doreik0";
}
if(localStorage["user_name"]==null){
localStorage["user_name"]="demo";
}
if(localStorage["pass"]==null){
localStorage["pass"]="demo";
}
if(localStorage["sound_alert"]==null){
localStorage["sound_alert"]="on";
}
if(localStorage["changed"]==null){
localStorage["changed"]="false";
}
if(localStorage["new_events"]==null){
localStorage["new_events"]=parseInt(localStorage["events"]);
}
}

View File

@ -0,0 +1,17 @@
console.log("hola");
var url = window.location.href;
var re = /\?event=(\d+)/;
console.log("hola");
if(re.exec(url)) {
if(!isNaN(RegExp.$1)) {
var eventId = RegExp.$1;
document.write(chrome.extension.getBackgroundPage().getNotification(eventId));
}
}
console.log("hola");
window.onload = function () {
setTimeout(function() {
window.close();
}, 10000);
}
console.log("hola");

View File

@ -0,0 +1,175 @@
function initialise(){
document.getElementById('ip_address').value = localStorage["ip_address"];
document.getElementById('api_pass').value = localStorage["api_pass"];
document.getElementById('user_name').value = localStorage["user_name"];
document.getElementById('pass').value = localStorage["pass"];
document.getElementById('critical').value = localStorage["critical"];
document.getElementById('informational').value = localStorage["informational"];
document.getElementById('maintenance').value = localStorage["maintenance"];
document.getElementById('normal').value = localStorage["normal"];
document.getElementById('warning').value = localStorage["warning"];
document.getElementById('refresh').value = localStorage["refresh"];
document.getElementById('events').value = localStorage["events"];
if(localStorage["sound_alert"]=="on"){
disable(false);
document.getElementById('sound_alert_o').checked=true;
}
if(localStorage["sound_alert"]=="off"){
disable(true);
document.getElementById('sound_alert_f').checked=true;
}
}
function change(value, id){
playSound(value);
if(id=="critical"){
localStorage["critical"]=value;
}
if(id=="informational"){
localStorage["informational"]=value;
}
if(id=="maintenance"){
localStorage["maintenance"]=value;
}
if(id=="normal"){
localStorage["normal"]=value;
}
if(id=="warning"){
localStorage["warning"]=value;
}
}
function change_o(value, id){
if(id=="refresh"){
localStorage["refresh"]=value;
}
if(id=="events"){
localStorage["events"]=value;
}
}
function change_global(value,id){
console.log("value => "+value);
console.log("id => "+id);
bg=chrome.extension.getBackgroundPage();
bg.location.reload();
if(id=="ip_address"){
localStorage["ip_address"]=value;
}
if(id=="api_pass"){
localStorage["api_pass"]=value;
}
if(id=="user_name"){
localStorage["user_name"]=value;
}
if(id=="pass"){
localStorage["pass"]=value;
}
if(id=="sound_alert"){
localStorage["sound_alert"]=value;
if(localStorage["sound_alert"]=="off"){
disable(true);
}
if(localStorage["sound_alert"]=="on"){
disable(false);
}
}
}
function disable(state){
if(state){
document.getElementById("critical").disabled=true;
document.getElementById("informational").disabled=true;
document.getElementById("maintenance").disabled=true;
document.getElementById("normal").disabled=true;
document.getElementById("warning").disabled=true;
}
if(!state){
document.getElementById("critical").disabled=false;
document.getElementById("informational").disabled=false;
document.getElementById("maintenance").disabled=false;
document.getElementById("normal").disabled=false;
document.getElementById("warning").disabled=false;
}
}
function windowClose() {
//window.close();
console.log("close");
}
//Add callbacks to elements
$(document).ready (function () {
//Initialise all form fields
initialise();
//IP address field
$("#ip_address").change(function () {
change_global($(this).val(), "ip_address");
});
//API password field
$("#api_pass").change(function () {
change_global($(this).val(), "api_pass");
});
//User name field
$("#user_name").change(function () {
change_global($(this).val(), "user_name");
});
//Password field
$("#pass").change(function () {
change_global($(this).val(), "pass");
});
//Sound alerts on/off
$("#sound_alert_o").change(function () {
change_global($(this).val(), "sound_alert");
});
$("#sound_alert_f").change(function () {
change_global($(this).val(), "sound_alert");
});
//Alert sounds fields
$("#critical").change(function () {
change($(this).val(), "critical");
});
$("#informational").change(function () {
change($(this).val(), "informational");
});
$("#maintenance").change(function () {
change($(this).val(), "maintenance");
});
$("#normal").change(function () {
change($(this).val(), "normal");
});
$("#warning").change(function () {
change($(this).val(), "warning");
});
//Auto refresh field
$("#refresh").change(function () {
change_o($(this).val(), "refresh");
});
$("#events").change(function () {
change_o($(this).val(), "events");
});
//Close button
$("#close").click (function () {
window.close();
});
});

View File

@ -0,0 +1,205 @@
var timer = null;
var event_array;
var max_events;
var bg;
$(document).ready(function(){
max_events=localStorage["events"];
if(localStorage["events"]==undefined){
localStorage["events"]="20";
}
bg=chrome.extension.getBackgroundPage();
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(mainPoP , 2000 );
});
function mainPoP(){
if(bg.check()){
showEvents();
}
else
{
showUrlError();
}
}
function showUrlError(){
var res=document.createDocumentFragment();
var r = document.getElementById('e');
var eve=document.createElement('div');
eve.id="event_temp";
eve.setAttribute("class","b");
var p = document.createElement('a');
p.href="options.html";
p.target="_blank";
p.innerText="Configure ip address,API password, user name and password with correct values";
eve.appendChild(p);
res.appendChild(eve);
r.parentNode.insertBefore(res,r);
$('.loader').hide();
$('div.b').show();
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(refresh , 1000 );
}
function showDataError(){
var res=document.createDocumentFragment();
var r = document.getElementById('e');
var eve=document.createElement('div');
eve.id="event_temp";
eve.setAttribute("class","b");
var p = document.createElement('a');
p.innerText="Error in fetching data!! Check your internet connection";
eve.appendChild(p);
res.appendChild(eve);
r.parentNode.insertBefore(res,r);
$('.loader').hide();
$('div.b').show();
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(refresh , 1000 );
}
function showEvents(){
var allEvents=bg.fetchEvents();
var r = document.getElementById('e');
var res=document.createDocumentFragment();
var eve=document.createElement('div');
eve.id="event_temp";
eve.setAttribute("class","b");
var i=0;
if(allEvents.length>0){
while(i<max_events){
var eve_title=document.createElement('div');
var img = document.createElement('img');
img.src = 'images/plus.gif';
img.width = '9';
img.height='9';
img.className ='pm';
img.id='i_' + i;
eve_title.appendChild(img);
var a = document.createElement('a');
var temp_style;
var agent_url;
if(allEvents[i][1]==""){;
agent_url=localStorage["ip_address"]+"/index.php?sec=eventos&sec2=operation/events/events" ;
}else{
agent_url=localStorage["ip_address"]+"/index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente="+allEvents[i][1];
}
a.setAttribute("href",agent_url);
a.target="_blank";
a.innerText = allEvents[i][6];
if(i<localStorage["new_events"]){
var temp_style="font-weight:bold;";
}
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.appendChild(eve_title);
var b = document.createElement('br');
eve.appendChild(b);
var time=allEvents[i][5].split(" ");
var time_text = time[0]+" "+time[1];
var p = document.createElement('p');
var id;
if(allEvents[i][9]==0){
id=".";
}
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.id = 'p_' + i;
eve.appendChild(p);
i++;
}
res.appendChild(eve);
r.parentNode.insertBefore(res,r);
$('img.pm').click(showHide);
$('.loader').hide();
$('div.b').show();
}
else{
showDataError();
}
localStorage["new_events"]=0;
bg.hideBadge();
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(refresh , 30*1000 );
}
function showHide() {
var id = $(this).attr('id');
var num = id.split("_")[1];
var pid = "p_" + num;
if($('#' + pid).css('display') == 'none') {
$('#' + pid).slideDown("fast");
$(this).attr({src: 'images/minus.gif'});
}
else {
$('#' + pid).slideUp("fast");
$(this).attr({src: 'images/plus.gif'});
}
}
function refresh(){
localStorage["new_events"]=0;
bg.hideBadge();
var e = document.getElementById('event_temp');
if(e){
e.parentNode.removeChild(e);
}
mainPoP();
}
function mrefresh(){
localStorage["new_events"]=0;
bg.hideBadge();
var bg=chrome.extension.getBackgroundPage();
bg.location.reload();
var e = document.getElementById('event_temp');
if(e){
e.parentNode.removeChild(e);
}
mainPoP();
}

View File

@ -1,6 +1,7 @@
{
"name": "__MSG_name__",
"version": "1.1",
"version": "1.2",
"manifest_version": 2,
"description": "__MSG_description__",
"homepage_url": "http://pandorafms.com",
"browser_action": {
@ -25,4 +26,4 @@
"background"
],
"default_locale": "en"
}
}

View File

@ -16,21 +16,7 @@
<body>
<h1>Event Alert</h1>
<div id="e" style="background:url('images/icon.png') no-repeat 0% 50%; margin:0 4px; padding-left:50px; min-height:48px;">
<script type="text/javascript">
var url = window.location.href;
var re = /\?event=(\d+)/;
if(re.exec(url)) {
if(!isNaN(RegExp.$1)) {
var eventId = RegExp.$1;
document.write(chrome.extension.getBackgroundPage().getNotification(eventId));
}
}
window.onload = function () {
setTimeout(function() {
window.close();
}, 10000);
}
</script>
<script src="js/notification.js"></script>
</div>
</body>
</html>

View File

@ -1,110 +1,14 @@
<!doctype html>
<html>
<head>
<head>
<title>Pandora FMS extension</title>
<link rel="stylesheet" href="css/popup.css" type="text/css" />
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/sound.js"></script>
<script type="text/javascript">
$(document).ready(function(){
document.getElementById('ip_address').value = localStorage["ip_address"];
document.getElementById('api_pass').value = localStorage["api_pass"];
document.getElementById('user_name').value = localStorage["user_name"];
document.getElementById('pass').value = localStorage["pass"];
document.getElementById('critical').value = localStorage["critical"];
document.getElementById('informational').value = localStorage["informational"];
document.getElementById('maintenance').value = localStorage["maintenance"];
document.getElementById('normal').value = localStorage["normal"];
document.getElementById('warning').value = localStorage["warning"];
document.getElementById('refresh').value = localStorage["refresh"];
document.getElementById('events').value = localStorage["events"];
if(localStorage["sound_alert"]=="on"){
disable(false);
document.getElementById('sound_alert_o').checked=true;
}
if(localStorage["sound_alert"]=="off"){
disable(true);
document.getElementById('sound_alert_f').checked=true;
}
$("#demo [title]").tooltip();
});
function change(value, id){
playSound(value);
if(id=="critical"){
localStorage["critical"]=value;
}
if(id=="informational"){
localStorage["informational"]=value;
}
if(id=="maintenance"){
localStorage["maintenance"]=value;
}
if(id=="normal"){
localStorage["normal"]=value;
}
if(id=="warning"){
localStorage["warning"]=value;
}
}
function change_o(value, id){
if(id=="refresh"){
localStorage["refresh"]=value;
}
if(id=="events"){
localStorage["events"]=value;
}
}
function change_global(value,id){
bg=chrome.extension.getBackgroundPage();
bg.location.reload();
if(id=="ip_address"){
localStorage["ip_address"]=value;
}
if(id=="api_pass"){
localStorage["api_pass"]=value;
}
if(id=="user_name"){
localStorage["user_name"]=value;
}
if(id=="pass"){
localStorage["pass"]=value;
}
if(id=="sound_alert"){
localStorage["sound_alert"]=value;
if(localStorage["sound_alert"]=="off"){
disable(true);
}
if(localStorage["sound_alert"]=="on"){
disable(false);
}
}
}
function disable(state){
if(state){
document.getElementById("critical").disabled=true;
document.getElementById("informational").disabled=true;
document.getElementById("maintenance").disabled=true;
document.getElementById("normal").disabled=true;
document.getElementById("warning").disabled=true;
}
if(!state){
document.getElementById("critical").disabled=false;
document.getElementById("informational").disabled=false;
document.getElementById("maintenance").disabled=false;
document.getElementById("normal").disabled=false;
document.getElementById("warning").disabled=false;
}
}
</script>
<script src="js/options.js"></script>
<script src="js/popup.js"></script>
</head>
<body>
<div id="demo">
<div class="options_header">
<img src="images/logo.png">
@ -112,34 +16,34 @@
<div class="options_divider"><h2>Options Menu</h2></div>
<div class="options_textarea">
<table width=450px>
<table width=600px>
<caption><h3>Global Parameters</h3></caption>
<tr>
<td title="IP address of server eg: http://127.0.0.1/pandora_console" style="cursor:help">IP Address</td>
<td><input type="text" size=50px name="ip_address" id="ip_address" onChange="change_global(this.value, 'ip_address');"> </td>
<td title="IP address of server eg: http://127.0.0.1/pandora_console" style="cursor:help">Console URL</td>
<td><input type="text" size=50px name="ip_address" id="ip_address"> </td>
</tr>
<tr>
<td title="API password of the server" style="cursor:help">API Password</td>
<td><input type="password" size=50px name="api_pass" id="api_pass" onChange="change_global(this.value, 'api_pass');" ></td>
<td><input type="password" size=50px name="api_pass" id="api_pass" ></td>
</tr>
<tr>
<td title="A valid user name" style="cursor:help">User name</td>
<td> <input type="text" size=50px name="user_name" id="user_name" onChange="change_global(this.value, 'user_name');"> </td>
<td> <input type="text" size=50px name="user_name" id="user_name"> </td>
</tr>
<tr>
<td title="Password" style="cursor:help">Password</td>
<td> <input type="password" size=50px name="pass" id="pass" onChange="change_global(this.value, 'pass');"> </td>
<td> <input type="password" size=50px name="pass" id="pass"> </td>
</tr>
</table>
</div>
<div class="options_textarea">
<table width=450px>
<caption><h3>Event Alert Sounds Configuration</h3></caption>
<tr>
<td title="All sound alerts of notifications on/off" style="cursor:help">Sound Alerts </td>
<td>
<input type="radio" id="sound_alert_o" name="sound_alert" value="on" onChange="change_global(this.value, 'sound_alert');"/> On
<input type="radio" id="sound_alert_f" name="sound_alert" value="off" onChange="change_global(this.value, 'sound_alert');"/> Off
<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
</td>
</tr>
@ -150,7 +54,7 @@
<tr>
<td>Critical</td>
<td>
<select id="critical" onChange="change(this.options[selectedIndex].value, 'critical');">
<select id="critical">
<option value="1">Air Craft Alarm</option>
<option value="2">Air Shock Alarm</option>
<option value="3">Alien Alarm</option>
@ -168,7 +72,7 @@
<tr>
<td>Informational</td>
<td>
<select id="informational" onChange="change(this.options[selectedIndex].value, 'informational');">
<select id="informational">
<option value="1">Air Craft Alarm</option>
<option value="2">Air Shock Alarm</option>
<option value="3">Alien Alarm</option>
@ -186,7 +90,7 @@
<tr>
<td>Maintenance</td>
<td>
<select id="maintenance" onChange="change(this.options[selectedIndex].value, 'maintenance');">
<select id="maintenance">
<option value="1">Air Craft Alarm</option>
<option value="2">Air Shock Alarm</option>
<option value="3">Alien Alarm</option>
@ -204,7 +108,7 @@
<tr>
<td>Normal</td>
<td>
<select id="normal" onChange="change(this.options[selectedIndex].value, 'normal');">
<select id="normal">
<option value="1">Air Craft Alarm</option>
<option value="2">Air Shock Alarm</option>
<option value="3">Alien Alarm</option>
@ -222,7 +126,7 @@
<tr>
<td>Warning</td>
<td>
<select id="warning" onChange="change(this.options[selectedIndex].value,'warning');">
<select id="warning">
<option value="1">Air Craft Alarm</option>
<option value="2">Air Shock Alarm</option>
<option value="3">Alien Alarm</option>
@ -240,7 +144,7 @@
<tr>
<td title="Automatic Refresh time to fetch new events" style="cursor:help">Auto Refresh Time</td>
<td>
<select id="refresh" onChange="change_o(this.options[selectedIndex].value,'refresh');">
<select id="refresh">
<option value="5">5 seconds</option>
<option value="10">10 seconds</option>
<option value="15">15 seconds</option>
@ -257,7 +161,7 @@
<tr>
<td title="Number of events to be displayed in pop up window" style="cursor:help">Number of events</td>
<td>
<select id="events" onChange="change_o(this.options[selectedIndex].value,'events');">
<select id="events">
<option value="5">5</option>
<option value="10">10</option>
<option value="12">12</option>
@ -269,12 +173,10 @@
</td>
</tr>
</table>
<button type="button" onclick="window.close()"><h3>Close</h3></button>
<p style="font-family:arial;font-style:italic;color:black;font-size:11px;">Author Information : R.Hareesan (rharishan@gmail.com)</p>
</div>
<script src="js/popup.js"></script>
</head>
<body>
<div class="options_footer">
<button id="close" type="button"><h3>Close</h3></button>
<p style="font-family:arial;font-style:italic;color:black;font-size:11px;">Author Information : R.Hareesan (rharishan@gmail.com)</p>
</div>
</body>
</html>

View File

@ -2,216 +2,7 @@
<head>
<link rel="stylesheet" href="css/popup.css" type="text/css" />
<script src="js/jquery-1.7.2.min.js"></script>
<script>
var timer = null;
var event_array;
var max_events;
var bg;
$(document).ready(function(){
max_events=localStorage["events"];
if(localStorage["events"]==undefined){
localStorage["events"]="20";
}
bg=chrome.extension.getBackgroundPage();
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(mainPoP , 2000 );
});
function mainPoP(){
if(bg.check()){
showEvents();
}
else
{
showUrlError();
}
}
function showUrlError(){
var res=document.createDocumentFragment();
var r = document.getElementById('e');
var eve=document.createElement('div');
eve.id="event_temp";
eve.setAttribute("class","b");
var p = document.createElement('a');
p.href="options.html";
p.target="_blank";
p.innerText="Configure ip address,API password, user name and password with correct values";
eve.appendChild(p);
res.appendChild(eve);
r.parentNode.insertBefore(res,r);
$('.loader').hide();
$('div.b').show();
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(refresh , 1000 );
}
function showDataError(){
var res=document.createDocumentFragment();
var r = document.getElementById('e');
var eve=document.createElement('div');
eve.id="event_temp";
eve.setAttribute("class","b");
var p = document.createElement('a');
p.innerText="Error in fetching data!! Check your internet connection";
eve.appendChild(p);
res.appendChild(eve);
r.parentNode.insertBefore(res,r);
$('.loader').hide();
$('div.b').show();
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(refresh , 1000 );
}
function showEvents(){
var allEvents=bg.fetchEvents();
var r = document.getElementById('e');
var res=document.createDocumentFragment();
var eve=document.createElement('div');
eve.id="event_temp";
eve.setAttribute("class","b");
var i=0;
if(allEvents.length>0){
while(i<max_events){
var eve_title=document.createElement('div');
var img = document.createElement('img');
img.src = 'images/plus.gif';
img.width = '9';
img.height='9';
img.className ='pm';
img.id='i_' + i;
eve_title.appendChild(img);
var a = document.createElement('a');
var temp_style;
var agent_url;
if(allEvents[i][1]==""){;
agent_url=localStorage["ip_address"]+"/index.php?sec=eventos&sec2=operation/events/events" ;
}else{
agent_url=localStorage["ip_address"]+"/index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente="+allEvents[i][1];
}
a.setAttribute("href",agent_url);
a.target="_blank";
a.innerText = allEvents[i][6];
if(i<localStorage["new_events"]){
var temp_style="font-weight:bold;";
}
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.appendChild(eve_title);
var b = document.createElement('br');
eve.appendChild(b);
var time=allEvents[i][5].split(" ");
var time_text = time[0]+" "+time[1];
var p = document.createElement('p');
var id;
if(allEvents[i][9]==0){
id=".";
}
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.id = 'p_' + i;
eve.appendChild(p);
i++;
}
res.appendChild(eve);
r.parentNode.insertBefore(res,r);
$('img.pm').click(showHide);
$('.loader').hide();
$('div.b').show();
}
else{
showDataError();
}
localStorage["new_events"]=0;
bg.hideBadge();
if(timer) {
clearTimeout(timer);
}
timer =setTimeout(refresh , 30*1000 );
}
function showHide() {
var id = $(this).attr('id');
var num = id.split("_")[1];
var pid = "p_" + num;
if($('#' + pid).css('display') == 'none') {
$('#' + pid).slideDown("fast");
$(this).attr({src: 'images/minus.gif'});
}
else {
$('#' + pid).slideUp("fast");
$(this).attr({src: 'images/plus.gif'});
}
}
function refresh(){
localStorage["new_events"]=0;
bg.hideBadge();
var e = document.getElementById('event_temp');
if(e){
e.parentNode.removeChild(e);
}
mainPoP();
}
function mrefresh(){
localStorage["new_events"]=0;
bg.hideBadge();
var bg=chrome.extension.getBackgroundPage();
bg.location.reload();
var e = document.getElementById('event_temp');
if(e){
e.parentNode.removeChild(e);
}
mainPoP();
}
</script>
<script src="js/popup.js"></script>
</head>
<body>
<div>