-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_map.php
More file actions
428 lines (349 loc) · 13.5 KB
/
create_map.php
File metadata and controls
428 lines (349 loc) · 13.5 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
<?php
include "config.php";
include "layout.class.php";
include "bartlby-ui.class.php";
$btl=new BartlbyUi($Bartlby_CONF);
$info=$btl->getInfo();
$layout= new Layout();
$layout->setTemplate("nonav.html");
?>
<script type="text/javascript" src="js/dom-drag.js"></script>
<script type="text/javascript">
/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip
var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).
document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="themes/<?php echo $layout->theme?>/images/arrow2.gif">') //write out pointer image
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""
function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}
function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20
var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY
var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000
//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}
//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}
function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}
document.onmousemove=positiontip
</script>
<style type="text/css">
#dhtmltooltip{
position: absolute;
left: -300px;
width: 150px;
border: 1px solid black;
padding: 2px;
background-color: lightyellow;
visibility: hidden;
z-index: 100;
/*Remove below line to remove shadow. Below line should always appear last within this CSS*/
filter: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135);
}
#dhtmlpointer{
position:absolute;
left: -300px;
z-index: 101;
visibility: hidden;
}
</style>
<script>
var layer_array = new Array();
var active_layer=null;
var layerCount=0;
function pushLayer(la) {
layer_array.push(la);
layerCount++;
}
function layer_pos() {
document.storeit.storeString.value='';
for(x=0; x<layer_array.length; x++) {
if(layer_array[x].innerHTML != "") {
document.storeit.storeString.value += "$layer["+layer_array[x].id+"][top]='" + layer_array[x].style.top +"';\n";
document.storeit.storeString.value += "$layer["+layer_array[x].id+"][left]='" + layer_array[x].style.left +"';\n";
document.storeit.storeString.value += "$layer["+layer_array[x].id+"][title]='" + layer_array[x].title +"';\n";
}
}
document.storeit.submit();
}
function addLayer(title, HTML) {
var newElem = document.createElement("div"); // neues DIV-Tag erstellen
newElem.setAttribute("style", "position:relative; width:100px; height: 100px;"); // DIV stylen
newElem.setAttribute("id", "uniq"+layerCount); // DIV eine ID geben, damit später noch darauf zugegriffen werden kann
newElem.innerHTML = HTML; // HTML-Code in das DIV einfügen
newElem.title=title;
//newElem.onDblClick=function() {RemoveLayer(newElem)};
newElem.setAttribute("onDblClick", "RemoveLayer(" + newElem.id + ")", true);
//"RemoveLayer(" + newElem + ")"
document.getElementsByTagName("body")[0].appendChild(newElem); // DIV-Tag in den Body einfügen
Drag.init(newElem);
pushLayer(newElem);
return newElem.id;
}
function addLayerForm() {
capt=document.addfm.newCaption.value;
ico=document.addfm.icon[document.addfm.icon.selectedIndex].value;
addTitleIcon(capt, ico);
cancelAddLayer();
}
function addTitleIcon(capt, ico) {
title=capt + "/" + ico;
return addLayer(title, "<img src='server_icons/"+ico+"'><br>" + capt);
}
function showAdd() {
cancelLayerOpts();
var obj = document.getElementById("addNew");
obj.style.visibility = "visible";
}
function cancelAddLayer() {
var obj = document.getElementById("addNew");
obj.style.visibility = "hidden";
}
function RemoveLayer(wich) {
active_layer=wich;
showLayerOpts();
}
function showLayerOpts() {
cancelAddLayer();
var obj = document.getElementById("layeropts");
obj.style.visibility = "visible";
}
function cancelLayerOpts() {
var obj = document.getElementById("layeropts");
obj.style.visibility = "hidden";
}
function ModifyLayer() {
alert("Modify: " + active_layer.id);
}
function RemoLayer() {
//alert("Remove:" + active_layer.id);
if(active_layer.id.substring(0, 6) == "server") {
alert("servers can't be deleted");
} else {
active_layer.innerHTML="";
}
cancelLayerOpts();
}
function repositionIT() {
/* echo "var layerTop = new Array();\n";
echo "var layerLeft = new Array();\n";
echo "var layerTitle = new Array();\n";
echo "var layerId = new Array();\n";
*/
for(x=0; x<layerTop.length; x++) {
obj = document.getElementById(layerId[x]);
if(obj) {
obj.style.top=layerTop[x];
obj.style.left=layerLeft[x];
} else {
//Add a new One :-)
ar=layerTitle[x].split("/");
obj = document.getElementById(addTitleIcon(ar[0], ar[1]));
obj.style.top=layerTop[x];
obj.style.left=layerLeft[x];
}
}
}
</script>
<input type="button" onClick='layer_pos();' value="Store">
<input type="button" onClick='showAdd();' value="Add">
<?php
$layout->Table("100%");
$server_ico="<select name='icon'>";
$dhl=opendir("server_icons");
while($file = readdir($dhl)) {
//$sr=bartlby_get_server_by_id($btl->RES, $k);
//$isup=$btl->isServerUp($k);
//if($isup == 1 ) { $isup="UP"; } else { $isup="DOWN"; }
if(preg_match("/.*\.[png|gif]/", $file)) {
$server_ico .="<option value='$file'>$file</option>";
}
}
closedir($dhl);
$server_ico .="</select>";
$map=$btl->getSVCMap();
$ssum=0;
while(list($server, $svcs) = each($map)) {
if($btl->isServerUp($svcs[0][server_id], $map)) {
$is_up="green";
} else {
$is_up="red";
}
$qck[$svcs[0][server_name]][0]=0;
$qck[$svcs[0][server_name]][1]=0;
$qck[$svcs[0][server_name]][2]=0;
$qck[$svcs[0][server_name]][downtime]=0;
$qck[$svcs[0][server_name]][acks]=0;
for($y=0; $y<count($svcs); $y++) {
$ssum++;
$qck[$svcs[$y][server_name]][$svcs[$y][current_state]]++;
$qck[$svcs[$y][server_name]][10]=$svcs[$y][server_id];
$qck[$svcs[$y][server_name]][server_icon]=$svcs[$y][server_icon];
if($svcs[$y][is_downtime] == 1) {
$qck[$svcs[$y][server_name]][$svcs[$y][current_state]]--;
$qck[$svcs[$y][server_name]][downtime]++;
}
if($svcs[$y][service_ack_current] == 2) {
$qck[$svcs[$y][server_name]][acks]++;
$acks_outstanding++;
}
}
$srvmsg = "<table><tr>";
$srvmsg .= "<tr><td colspan=2><b>" . $svcs[0][server_name] . "</b></td></tr>";
$srvmsg .= "<tr><td><font color=green>OK: </font></td><td>" . $qck[$svcs[0][server_name]][0] . "</td></tr>";
$srvmsg .= "<tr><td><font color=orange>Warning: </font></td><td>" . $qck[$svcs[0][server_name]][1] . "</td></tr>";
$srvmsg .= "<tr><td><font color=red>Critical: </font></td><td>" . $qck[$svcs[0][server_name]][2] . "</td></tr>";
$srvmsg .= "<tr><td>Downtimes: </td><td>" . $qck[$svcs[0][server_name]][downtime] . "</td></tr>";
$srvmsg .= "<tr><td>Acks outstanding: </td><td>" . $qck[$svcs[0][server_name]][acks] . "</td></tr>";
$srvmsg .= "</tr></table>";
$mover="ddrivetip('" . $srvmsg . "', 300);";
$mout="hideddrivetip();";
$layout->OUT .= "<div onClick=\"" . $mout . "\" onMouseOut=\"" . $mout . "\" onMouseOver=\"" . $mover . "\" xtitle='" . $svcs[0][server_name] . "/" . $svcs[0][server_icon] . "' onDblClick='RemoveLayer(this);' id='server" . $svcs[0][server_id] . "' style=\"position: relative;width:100px;height:100px\"><img src='server_icons/" . $svcs[0][server_icon] . "'><br><font color='$is_up'>" . $svcs[0][server_name] . "</font></div>\n";
$layout->OUT .= '<script type="text/javascript">var hndl' . $svcs[0][server_id] . '=document.getElementById("server' . $svcs[0][server_id] . '"); Drag.init(hndl' . $svcs[0][server_id] . ', null);pushLayer(hndl' . $svcs[0][server_id] . ');</script>' . "\n";
}
$layout->TableEnd();
//Load Defaults ;-)
$fp=@fopen("create_map.dat","r");
if($fp) {
while(!feof($fp)) {
$estr .= @fgets($fp, 1024);
}
}
@fclose($fp);
@eval($estr);
echo "<script>\n";
echo "var layerTop = new Array();\n";
echo "var layerLeft = new Array();\n";
echo "var layerTitle = new Array();\n";
echo "var layerId = new Array();\n";
echo "layerCount +=" . count($layer)+2 . ";";
$cnt=0;
while(list($k, $v) = @each($layer)) {
echo "layerTop[$cnt] = '" . $v[top] . "';\n";
echo "layerLeft[$cnt] = '" . $v[left] . "';\n";
echo "layerTitle[$cnt] = '" . $v[title] . "';\n";
echo "layerId[$cnt] = '" . $k . "';\n";
$cnt++;
}
reset($map);
echo "</script>\n";
$srvmsg = "<table><tr>";
$srvmsg .= "<tr><td colspan=2><b>Bartlby</b></td></tr>";
$srvmsg .= "<tr><td>Servers: </td><td>" . count($map) . "</td></tr>";
$srvmsg .= "<tr><td>Services: </td><td>" . $ssum . "</td></tr>";
$srvmsg .= "<tr><td>Uptime: </td><td>" . $btl->intervall(time()-$btl->info[startup_time]) . "</td></tr>";
$srvmsg .= "</tr></table>";
$mover="ddrivetip('" . $srvmsg . "', 300);";
$mout="hideddrivetip();";
echo '<div onMouseOut="' . $mout . '" onMouseOver="' . $mover . '" id="bartlby" style="position: relative; left:0; top:0;width:100px;height:100px"><img src="themes/' . $layout->theme . '/images/btl-logo.gif"></div>';
echo $layout->OUT;
?>
<script language="javascript">
var aThumb = document.getElementById("bartlby");
pushLayer(aThumb);
Drag.init(aThumb, null);
repositionIT();
</script>
<div id="addNew" style="visibility:hidden; position: absolute; height: 300px; width: 200px; left: 412px; top:100px; color:#000000; background-color: yellow; z-index:3;">
<form name="addfm">
<table width=100%>
<tr>
<td colspan=2><b>Add Element</td>
</tr>
<tr>
<td>Caption:</td>
<td><input type=text name="newCaption"></td>
</tr>
<tr>
<td>Icon:</td>
<td><?php echo $server_ico?></td>
</tr>
<tr>
<td colspan=2><input type="button" value="add" onClick="addLayerForm();">
<input type="button" value="cancel" onClick="cancelAddLayer();">
</td>
</tr>
</table>
</form>
</div>
<div id="layeropts" style="visibility:hidden; position: absolute; height: 300px; width: 200px; left: 412px; top:100px; color:#000000; background-color: yellow; z-index:3;">
<form name="layeroptsfm">
<table width=100%>
<tr>
<td colspan=2><input type="button" value="remove" onClick="RemoLayer();">
<input type="button" value="cancel" onClick="cancelLayerOpts();">
</td>
</tr>
</table>
</form>
</div>
<div id="output" style="visibility:hidden; position: absolute; height: 300px; width: 200px; left: 600; top:100px; color:#000000; background-color: yellow; z-index:3;">
<form method=post name="storeit" action='bartlby_action.php'>
<input type=hidden name='action' value='storeMap'>
<textarea name='storeString' cols=50 rows=20>
</textarea>
</form>
</div>