-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.html
More file actions
307 lines (263 loc) · 16.2 KB
/
client.html
File metadata and controls
307 lines (263 loc) · 16.2 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<title>Monitoring</title>
<style>
.card-header{
text-align:center;
}
</style>
</head>
<body id="body" class="bg-light">
<div id="alert"><div id="clost" class="alert alert-danger"><div class="row"><div class="col"><strong>Connection to "ws://127.0.0.1:8080" lost</strong></div><div class="col"><button type="button" class="btn btn-success btn-sm" onclick="window.location.assign('http://monitor.saretzki.work/client/')" style="width: 100%;">Download Monitoring Client</button></div><div class="col" style="text-align: right;"><button type="button" class="btn btn-danger btn-sm" onclick="webs = websock();" style="width: 150px;">Reconnect</button></div></div></div></div>
<div id="connect" style="display:initial;">
<div class="card bg-dark text-light" style="margin: 10px;">
<div class="card-header">Server</div>
<div class="card-body">
<div class="form-group">
<label for="ws">Websocket Server:</label>
<input type="Text" class="form-control" placeholder="Enter Websocket Server URL z.B.: ws://127.0.0.1:8080" id="ws">
</div>
<button type="button" class="btn btn-danger btn-sm" onclick="setCookie(document.getElementById('ws').value)" style="width: 100%;">Save</button>
</div>
</div>
</div>
<div id="client" style="display:none;">
<div style="margin:15px;">
<div class="row">
<div class="col">
<h3 id="ti">
0/0/0
</h3>
</div>
<div class="col">
<button type="button" class="btn btn-success btn-sm" onclick="window.location.assign('http://monitor.saretzki.work/client/')" style="width: 100%;">Download Monitoring Client</button>
</div>
<div class="col" style="text-align: right;">
<a>Intervall:</a>
<button type="button" class="btn btn-primary btn-sm" onclick="sendaction('sleepminus','')" style="width: 26px;">-</button>
<a id="sleep">1</a>
<button type="button" class="btn btn-primary btn-sm" onclick="sendaction('sleepplus','')" style="width: 26px;">+</button>
</div>
</div>
</div>
<div class="card bg-dark text-light" style="margin: 10px;">
<div class="card-header">CPU</div>
<div class="card-body"><div id="cpu" style=""></div>
<div id="cpu_button">
<button type="button" class="btn btn-danger btn-sm" onclick="" style="width: 100%;">Disable CPU Monitoring</button>
</div>
</div>
</div>
<div class="card bg-dark text-light" style="margin: 10px;">
<div class="card-header">RAM</div>
<div class="card-body"><div class="progress bg-secondary" style="height:20px;margin-bottom: 10px;"><div id="mem" class="progress-bar progress-bar-striped bg-success" style="height:20px;width:0%"></div> </div>
<div id="mem_button">
<button type="button" class="btn btn-danger btn-sm" onclick="" style="width: 100%;">Disable RAM Monitoring</button>
</div>
</div>
</div>
<div class="card bg-dark text-light" style="margin: 10px;">
<div class="card-header">STORAGE</div>
<div class="card-body">
<div id="speicher" style=""></div>
<div class="row" id="speicher_button">
<div class="col">
<button type="button" class="btn btn-danger btn-sm" onclick="" style="width: 100%;">Disable CPU Monitoring</button>
</div>
<div class="col">
<button type="button" class="btn btn-danger btn-sm" onclick="" style="width: 100%;">Disable CPU Monitoring</button>
</div>
<div class="col">
<button type="button" class="btn btn-danger btn-sm" onclick="" style="width: 100%;">Disable CPU Monitoring</button>
</div>
<div class="col">
<button type="button" class="btn btn-danger btn-sm" onclick="" style="width: 100%;">Disable CPU Monitoring</button>
</div>
</div>
</div>
</div>
</div>
<script>
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function sleepFor( sleepDuration ){
var now = new Date().getTime();
while(new Date().getTime() < now + sleepDuration){ /* do nothing */ }
}
function log(msg) {
console.log(msg );
}
function update(msg) {
const obj = JSON.parse(msg);
document.getElementById('ti').innerText = ""+obj.time;
document.getElementById('sleep').innerText = obj.sleep;
document.getElementById('speicher').innerHTML = "";
document.getElementById('cpu_button').innerHTML = "";
document.getElementById('mem_button').innerHTML = "";
document.getElementById('speicher_button').innerHTML = "";
if (obj.mem.enabled)
document.getElementById('mem_button').innerHTML +='<button type="button" style="width: 100%;" class="btn btn-danger btn-sm" onclick="sendaction('+"'disable','MEM'"+')" style="">MEM</button>';
else
document.getElementById('mem_button').innerHTML +='<button type="button" style="width: 100%;" class="btn btn-success btn-sm" onclick="sendaction('+"'enable','MEM'"+')" style="">MEM</button>';
if (obj.cpu["enabled"])
document.getElementById('cpu_button').innerHTML +='<button type="button" style="width: 100%;" class="btn btn-danger btn-sm" onclick="sendaction('+"'disable','CPU'"+')" style="">CPU</button>';
else
document.getElementById('cpu_button').innerHTML +='<button type="button" style="width: 100%;" class="btn btn-success btn-sm" onclick="sendaction('+"'enable','CPU'"+')" style="">CPU</button>';
for (pfad in obj.speicher){
if (obj.speicher[pfad]["enabled"]){
document.getElementById('speicher').innerHTML += '<div class="progress bg-secondary" style="height:20px;margin-bottom: 10px;"><div id="sp_'+pfad+'" class="progress-bar progress-bar-striped " style="height:20px;width:'+obj.speicher[pfad]["used"][2]+'%">'+pfad+": "+ obj.speicher[pfad]["used"][0]+" " + obj.speicher[pfad]["used"][1]+ ' / '+ obj.speicher[pfad]["total"][0]+" " + obj.speicher[pfad]["total"][1]+ '</div> </div>';
document.getElementById('speicher_button').innerHTML +='<div class="col"><button type="button" class="btn btn-danger btn-sm" onclick="sendaction('+"'disable','"+(pfad.includes("\\")?pfad+"\\":pfad)+"'"+')" style="width: 100%;">'+pfad+'</button></div>';
if (obj.speicher[pfad]["error"]<=obj.speicher[pfad]["used"][2]){
document.getElementById('sp_'+pfad).classList.add("bg-danger")
document.getElementById('sp_'+pfad).classList.remove("bg-success")
document.getElementById('sp_'+pfad).classList.remove("bg-warning")
}else if (obj.speicher[pfad]["warning"]<=obj.speicher[pfad]["used"][2]){
document.getElementById('sp_'+pfad).classList.add("bg-warning")
document.getElementById('sp_'+pfad).classList.remove("bg-danger")
document.getElementById('sp_'+pfad).classList.remove("bg-success")
}else{
document.getElementById('sp_'+pfad).classList.remove("bg-warning")
document.getElementById('sp_'+pfad).classList.remove("bg-danger")
document.getElementById('sp_'+pfad).classList.add("bg-success")
}
}
else{
document.getElementById('speicher').innerHTML += '<div class="progress bg-secondary" style="height:20px;margin-bottom: 10px;"><div id="sp_'+pfad+'" class="progress-bar progress-bar-striped" style="height:20px;width:100%">'+pfad+ '</div> </div>';
document.getElementById('speicher_button').innerHTML +='<div class="col"><button type="button" class="btn btn-success btn-sm" onclick="sendaction('+"'enable','"+(pfad.includes("\\")?pfad+"\\":pfad)+"'"+')" style="width: 100%;">'+pfad+'</button></div>';
}
}
if (obj.cpu.enabled){
if (typeof(document.getElementById('cpu_platzhalter')) != 'undefined' && document.getElementById('cpu_platzhalter') != null) {
document.getElementById('cpu').innerHTML ="";
}
for (cpu in obj.cpu.use){
var element = document.getElementById('cpu_'+cpu);
if (!(typeof(element) != 'undefined' && element != null)) {
document.getElementById('cpu').innerHTML += '<div class="progress bg-secondary" style="height:20px;margin-bottom: 10px;"><div id="cpu_'+cpu+'"class="progress-bar progress-bar-striped '+(obj.cpu["error"]<obj.cpu.use[cpu]?"bg-danger":(obj.cpu["warning"]<obj.cpu.use[cpu]?"bg-warning":"bg-success"))+'" style="height:20px;width:'+obj.cpu.use[cpu]+'%">CPU'+cpu+": "+ obj.cpu.use[cpu]+'%</div> </div>';
log("create cpu_"+cpu)
} else {
if (obj.cpu["error"]<=obj.cpu.use[cpu]){
document.getElementById('cpu_'+cpu).classList.add("bg-danger")
document.getElementById('cpu_'+cpu).classList.remove("bg-success")
document.getElementById('cpu_'+cpu).classList.remove("bg-warning")
}else if (obj.cpu["warning"]<=obj.cpu.use[cpu]){
document.getElementById('cpu_'+cpu).classList.add("bg-warning")
document.getElementById('cpu_'+cpu).classList.remove("bg-danger")
document.getElementById('cpu_'+cpu).classList.remove("bg-success")
}else{
document.getElementById('cpu_'+cpu).classList.remove("bg-warning")
document.getElementById('cpu_'+cpu).classList.remove("bg-danger")
document.getElementById('cpu_'+cpu).classList.add("bg-success")
}
document.getElementById('cpu_'+cpu).style.width = obj.cpu.use[cpu]+'%'
document.getElementById('cpu_'+cpu).innerText = 'CPU'+cpu+': '+ obj.cpu.use[cpu]+'%';
}
}
}else{
document.getElementById('cpu').innerHTML ="";
document.getElementById('cpu').innerHTML += '<div id="cpu_platzhalter" class="progress bg-secondary" style="height:20px;margin-bottom: 10px;"><div id="cpu"class="progress-bar progress-bar-striped " style="height:20px;width:100%">CPU</div> </div>';
}
if (obj.mem.enabled){
if (obj.mem["error"]<=obj.mem.used[2]){
document.getElementById('mem').classList.add("bg-danger")
document.getElementById('mem').classList.remove("bg-success")
document.getElementById('mem').classList.remove("bg-warning")
}else if (obj.mem["warning"]<=obj.mem.used[2]){
document.getElementById('mem').classList.remove("bg-danger")
document.getElementById('mem').classList.remove("bg-success")
document.getElementById('mem').classList.add("bg-warning")
}else{
document.getElementById('mem').classList.remove("bg-danger")
document.getElementById('mem').classList.add("bg-success")
document.getElementById('mem').classList.remove("bg-warning")
}
document.getElementById('mem').style.width = obj.mem.used[2]+'%'
document.getElementById('mem').innerText = 'RAM: '+ obj.mem.used[0]+ obj.mem.used[1]+' / '+ obj.mem.total[0]+ obj.mem.total[1]+'';
}else{
document.getElementById('mem').innerText="RAM";
document.getElementById('mem').classList.remove("bg-danger")
document.getElementById('mem').classList.remove("bg-success")
document.getElementById('mem').classList.remove("bg-warning")
document.getElementById('mem').style.width ='100%'
}
}
function sendaction(a,tar){
log(a)
log(tar)
var send={action: a, target: tar}
log(send)
webs.send(JSON.stringify(send));
log(JSON.stringify(send))
}
function websock(){
// setup websocket with callbacks
var ws = new WebSocket(getCookie("websocket"));
ws.onopen = function() {
log('CONNECT');
document.getElementById('client').style.display ='initial'
document.getElementById('connect').style.display ='none'
document.getElementById('alert').innerHTML= "";
};
ws.onclose = function() {
log('DISCONNECT');
document.getElementById('client').style.display ='none'
document.getElementById('connect').style.display ='initial'
document.getElementById('alert').innerHTML= '<div id="clost" class="alert alert-danger"><div class="row"><div class="col"><strong>Connection to "'+getCookie("websocket")+'" lost</strong></div><div class="col"><button type="button" class="btn btn-success btn-sm" onclick="window.location.assign('+"'http://monitor.saretzki.work/client/'"+')" style="width: 100%;">Download Monitoring Client</button></div><div class="col" style="text-align: right;"><button type="button" class="btn btn-danger btn-sm" onclick="webs = websock();" style="width: 150px;">Reconnect</button></div></div></div>';
sleepFor( 1000 )
//webs = websock();
};
ws.onmessage = function(event) {
log('MESSAGE: ' + event.data);
update(event.data);
};
return ws;
}
function setCookie(server){
var d = new Date();
d.setTime(d.getTime() + (365*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = "websocket="+server+";" + expires + ";path=/";
checkCookie()
document.getElementById('alert').innerHTML= '<div id="clost" class="alert alert-warning"><div class="row"><div class="col"><strong>Connecting to "'+getCookie("websocket")+'" </strong></div><div class="col"><button type="button" class="btn btn-success btn-sm" onclick="window.location.assign('+"'http://monitor.saretzki.work/client/'"+')" style="width: 100%;">Download Monitoring Client</button></div><div class="col" style="text-align: right;"><button type="button" class="btn btn-danger btn-sm" onclick="webs = websock();" style="width: 150px;">Reconnect</button></div></div></div>';
try{
webs = websock();
}catch{
document.getElementById('alert').innerHTML= '<div id="clost" class="alert alert-danger"><div class="row"><div class="col"><strong>Connection to "'+getCookie("websocket")+'" lost</strong></div><div class="col"><button type="button" class="btn btn-success btn-sm" onclick="window.location.assign('+"'http://monitor.saretzki.work/client/'"+')" style="width: 100%;">Download Monitoring Client</button></div><div class="col" style="text-align: right;"><button type="button" class="btn btn-danger btn-sm" onclick="webs = websock();" style="width: 150px;">Reconnect</button></div></div></div>';
}
}
function checkCookie() {
if (getCookie("websocket") == "") {
var d = new Date();
d.setTime(d.getTime() + (365*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = "websocket=ws://127.0.0.1:8080;" + expires + ";path=/";
log("Setting Default Cookie")
}
}
checkCookie()
if (getCookie("websocket") == "") {
document.body.style = 'text-align: center';
document.body.innerHTML = '<h1>Diese Webseite braucht Cookies<br>Der Cookie konnte nicht gesetzt werden!</1> <h6>Chrome lässt keine Cookies von lokal geöffneten Dateien zu!<br><a href="http://monitor.saretzki.work">http://monitor.saretzki.work</a></h6>';
}else{
var webs = websock();
}
</script>
</body></html>