blob: 5eaa8c594bf5c5d92caf200b5bc9b1a3bce31f96 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/* Most widgets update their backend data every 10 seconds. 11 seconds
* will ensure that we update the GUI right after the stats are updated.
* Seconds * 1000 = value
*/
var update_interval = 11000;
function updateMeters() {
url = '/getstats.php'
new Ajax.Request(url, {
method: 'get',
onSuccess: function(transport) {
response = transport.responseText || "";
if (response != "")
stats(transport.responseText);
}
});
setTimeout('updateMeters()', update_interval);
}
function stats(x) {
var values = x.split("|");
if (values.find(function(value){
if (value == 'undefined' || value == null)
return true;
else
return false;
}))
return;
updateCPU(values[0]);
updateMemory(values[1]);
updateUptime(values[2]);
updateState(values[3]);
updateTemp(values[4]);
updateDateTime(values[5]);
updateInterfaceStats(values[6]);
updateInterfaces(values[7]);
updateGatewayStats(values[8]);
}
function updateMemory(x) {
if($('memusagemeter'))
$("memusagemeter").value = x + '%';
if($('memwidtha'))
$("memwidtha").style.width = x + 'px';
if($('memwidthb'))
$("memwidthb").style.width = (100 - x) + 'px';
}
function updateCPU(x) {
if($('cpumeter'))
$("cpumeter").value = x + '%';
if($('cpuwidtha'))
$("cpuwidtha").style.width = x + 'px';
if($('cpuwidthb'))
$("cpuwidthb").style.width = (100 - x) + 'px';
/* Load CPU Graph widget if enabled */
if(typeof GraphValue == 'function') {
GraphValue(graph[0], x);
}
}
function updateTemp(x) {
if($("tempmeter")) {
$("tempmeter").value = x + 'C';
$("tempwidtha").style.width = x + 'px';
$("tempwidthb").style.width = (100 - x) + 'px';
}
}
function updateDateTime(x) {
if($('datetime'))
$("datetime").firstChild.data = x;
}
function updateUptime(x) {
if($('uptime'))
$("uptime").value = x;
}
function updateState(x) {
if($('pfstate'))
$("pfstate").value = x;
}
function updateGatewayStats(x){
if (widgetActive("gateways")){
gateways_split = x.split(",");
var counter = 1;
for (var y=0; y<gateways_split.length-1; y++){
if($('gateway' + counter)) {
$('gateway' + counter).update(gateways_split[y]);
counter++;
}
}
}
}
function updateInterfaceStats(x){
if (widgetActive("interface_statistics")){
statistics_split = x.split(",");
var counter = 1;
for (var y=0; y<statistics_split.length-1; y++){
if($('stat' + counter)) {
$('stat' + counter).update(statistics_split[y]);
counter++;
}
}
}
}
function updateInterfaces(x){
if (widgetActive("interfaces")){
interfaces = x.split("~");
interfaces.each(function(iface){
details = iface.split(",");
switch(details[1]) {
case "up":
$(details[0] + '-up').style.display = "inline";
$(details[0] + '-down').style.display = "none";
$(details[0] + '-block').style.display = "none";
$(details[0] + '-ip').update(details[2]);
$(details[0] + '-media').update(details[3]);
break;
case "down":
$(details[0] + '-down').style.display = "inline";
$(details[0] + '-up').style.display = "none";
$(details[0] + '-block').style.display = "none";
$(details[0] + '-ip').update(details[2]);
$(details[0] + '-media').update(details[3]);
break;
case "block":
$(details[0] + '-block').style.display = "inline";
$(details[0] + '-down').style.display = "none";
$(details[0] + '-up').style.display = "none";
break;
}
});
}
}
function widgetActive(x) {
var widget = $(x + '-container');
if (widget.style.display != "none")
return true;
else
return false;
}
/* start updater */
document.observe('dom:loaded', function(){
setTimeout('updateMeters()', update_interval);
});
|