2019-04-15 09:18:41 +02:00
|
|
|
|
Object.values = function(o) {
|
|
|
|
|
var values = [];
|
|
|
|
|
for(var property in o) {
|
|
|
|
|
values.push(o[property]);
|
|
|
|
|
}
|
|
|
|
|
return values;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-18 08:12:54 +01:00
|
|
|
|
function SKYAPI(baseurl){
|
|
|
|
|
|
|
|
|
|
this.baseurl = baseurl;
|
|
|
|
|
this.refresh = []
|
|
|
|
|
|
|
|
|
|
this.setBaseURL = function(url){ this.baseurl = url; }
|
|
|
|
|
this.addRefresh = function( rh, seconds = null ){ this.refresh.push( { interval: seconds ? seconds : 5, refresh: rh } ); }
|
|
|
|
|
|
2019-04-08 08:47:12 +02:00
|
|
|
|
this.get = function(page, json, handler = null){ return this.__request("GET", page, json, handler); }
|
|
|
|
|
this.post = function(page, json, handler = null){ return this.__request("POST", page, json, handler); }
|
|
|
|
|
this.put = function(page, json, handler = null){ return this.__request("PUT", page, json, handler); }
|
|
|
|
|
|
|
|
|
|
this.__request = function(method, page, json, handler = null){
|
|
|
|
|
if (page[0] == '/')
|
|
|
|
|
page = page.substr(1);
|
|
|
|
|
|
2019-03-18 08:12:54 +01:00
|
|
|
|
var x = new XMLHttpRequest();
|
|
|
|
|
if (handler != null)
|
|
|
|
|
{
|
|
|
|
|
x.onload = function(){
|
|
|
|
|
var responseText = x.responseText;
|
2019-04-08 08:47:12 +02:00
|
|
|
|
if (json && !content)
|
|
|
|
|
handler( JSON.parse( responseText ) );
|
|
|
|
|
else
|
|
|
|
|
handler( responseText );
|
2019-03-18 08:12:54 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-08 08:47:12 +02:00
|
|
|
|
x.open(method, this.baseurl + page);
|
|
|
|
|
|
|
|
|
|
if (json)
|
|
|
|
|
x.send(JSON.stringify(json));
|
|
|
|
|
else
|
|
|
|
|
x.send();
|
2019-03-18 08:12:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.getJson = function(page, handler){
|
|
|
|
|
var j = function(t){
|
|
|
|
|
handler(JSON.parse(t));
|
|
|
|
|
};
|
2019-04-08 08:47:12 +02:00
|
|
|
|
return this.get( page, null, j );
|
2019-03-18 08:12:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.call = function(endpoint,method,parameters = [], receiver = null){
|
|
|
|
|
var x = new XMLHttpRequest();
|
|
|
|
|
|
|
|
|
|
x.open("POST", this.baseurl + endpoint, (receiver != null));
|
|
|
|
|
x.setRequestHeader("content-type","application/json");
|
|
|
|
|
|
|
|
|
|
if (receiver)
|
|
|
|
|
{
|
|
|
|
|
x.onload = function(){ var r = JSON.parse(this.responseText).Result; receiver(r); }
|
|
|
|
|
x.onerror = function(){ receiver(false); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var methodCall = {
|
|
|
|
|
"MethodName": method,
|
|
|
|
|
"Parameters": parameters
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
x.send(JSON.stringify(methodCall));
|
|
|
|
|
|
|
|
|
|
if (!receiver)
|
|
|
|
|
{
|
|
|
|
|
var result = JSON.parse(x.responseText);
|
|
|
|
|
if (result.Exception != null)
|
|
|
|
|
throw result.Exception;
|
|
|
|
|
|
|
|
|
|
return result.Result;
|
|
|
|
|
}
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.loadPage = function (page) {
|
2019-04-08 08:47:12 +02:00
|
|
|
|
if (page[0] == '/')
|
|
|
|
|
page = page.substr(1);
|
|
|
|
|
|
2019-03-18 08:12:54 +01:00
|
|
|
|
var x = new XMLHttpRequest();
|
2019-04-08 08:47:12 +02:00
|
|
|
|
|
2019-03-18 08:12:54 +01:00
|
|
|
|
x.open("GET", this.baseurl + page);
|
|
|
|
|
x.setRequestHeader("x-template-unframed","unframed");
|
|
|
|
|
x.onload = function()
|
|
|
|
|
{
|
|
|
|
|
$("#content").empty();
|
|
|
|
|
$("#content").append(this.responseText);
|
|
|
|
|
history.pushState(null, page, skyapi().baseurl + page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.refresh = []
|
|
|
|
|
|
|
|
|
|
x.send();
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.fireOnLoad = function(element){
|
|
|
|
|
if (element.onload != null)
|
|
|
|
|
{
|
|
|
|
|
element.onload();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var n=0;n<element.children.length;n++)
|
|
|
|
|
this.fireOnLoad(element.children[n]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.__refresh_index = 0;
|
|
|
|
|
this.UIRefresh = function(){
|
|
|
|
|
|
|
|
|
|
this.__refresh_index++;
|
|
|
|
|
|
|
|
|
|
for (var n=0;n<this.refresh.length;n++)
|
|
|
|
|
{
|
|
|
|
|
var r = this.refresh[n];
|
|
|
|
|
if ((this.__refresh_index % r.interval)==0)
|
|
|
|
|
r.refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setInterval( function(){ skyapi().UIRefresh(); }, 1000 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showStatistics(stats)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
$("#ServerTime").text("ServerTime: " + stats.ServerTime);
|
|
|
|
|
|
|
|
|
|
$("#indHttpServer").attr("state",stats.States.HttpServer);
|
|
|
|
|
$("#indManager").attr("state",stats.States.Manager);
|
|
|
|
|
$("#indCrawler").attr("state",stats.States.Crawler);
|
|
|
|
|
$("#indChecks").attr("state",stats.States.Checks);
|
|
|
|
|
$("#indDispatcher").attr("state",stats.States.Dispatcher);
|
|
|
|
|
|
|
|
|
|
$("#indHttpServer").attr("title",stats.States.HttpServer);
|
|
|
|
|
$("#indManager").attr("title",stats.States.Manager);
|
|
|
|
|
$("#indCrawler").attr("title",stats.States.Crawler);
|
|
|
|
|
$("#indChecks").attr("title",stats.States.Checks);
|
|
|
|
|
$("#indDispatcher").attr("title",stats.States.Dispatcher);
|
|
|
|
|
|
|
|
|
|
} catch (e)
|
|
|
|
|
{
|
|
|
|
|
$("#ServerTime").text("Server unreachable");
|
|
|
|
|
|
|
|
|
|
$("#indHttpServer").attr("state",3);
|
|
|
|
|
$("#indManager").attr("state",0);
|
|
|
|
|
$("#indCrawler").attr("state",0);
|
|
|
|
|
$("#indChecks").attr("state",0);
|
|
|
|
|
$("#indDispatcher").attr("state",0);
|
|
|
|
|
|
|
|
|
|
$("#indHttpServer").attr("title","UNKNOWN");
|
|
|
|
|
$("#indManager").attr("title","UNKNOWN");
|
|
|
|
|
$("#indCrawler").attr("title","UNKNOWN");
|
|
|
|
|
$("#indChecks").attr("title","UNKNOWN");
|
|
|
|
|
$("#indDispatcher").attr("title","UNKNOWN");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateStatistics()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var request = skyapi().call("api/management","GetStatistics",[],showStatistics);
|
|
|
|
|
} catch (e)
|
|
|
|
|
{
|
|
|
|
|
showStatistics(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var __skyapi = new SKYAPI("");
|
|
|
|
|
|
|
|
|
|
function skyapi()
|
|
|
|
|
{
|
|
|
|
|
return __skyapi;
|
|
|
|
|
}
|
2019-04-04 19:34:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function ScaleSI(value)
|
|
|
|
|
{
|
|
|
|
|
if (value > 1000000000)
|
|
|
|
|
return ((value / 1000000000) | 0) + "G";
|
|
|
|
|
if (value > 1000000)
|
|
|
|
|
return ((value / 1000000) | 0) + "M";
|
|
|
|
|
if (value > 1000)
|
|
|
|
|
return ((value / 1000) | 0) + "k";
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-04-15 09:18:41 +02:00
|
|
|
|
|
|
|
|
|
|