File: 1.09.1a/server/web/view.php (View as Code)

1: 2: /* ------------------------------------------------------------- 3: This file is part of FreeNATS 4: 5: FreeNATS is (C) Copyright 2008 PurplePixie Systems 6: 7: FreeNATS is free software: you can redistribute it and/or modify 8: it under the terms of the GNU General Public License as published by 9: the Free Software Foundation, either version 3 of the License, or 10: (at your option) any later version. 11: 12: FreeNATS is distributed in the hope that it will be useful, 13: but WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15: GNU General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with FreeNATS. If not, see www.gnu.org/licenses 19: 20: For more information see www.purplepixie.org/freenats 21: -------------------------------------------------------------- */ 22: 23: ob_start(); 24: require("include.php"); 25: $NATS->Start(); 26: $session=true; 27: if (!$NATS_Session->Check($NATS->DB)) 28: { 29: $session=false; 30: } 31: 32: $abs=GetAbsolute(); 33: 34: if (isset($_REQUEST['mode'])) $mode=$_REQUEST['mode']; 35: else $mode=""; 36: 37: $items=array(); // items 38: $ob=array(); // output buffer 39: 40: function show_output() 41: { 42: global $ob,$view,$mode; 43: foreach($ob as $oline) 44: { 45: echo $oline."
";
46: } 47: ob_end_flush(); 48: exit(); 49: } 50: 51: $q="SELECT * FROM fnview WHERE viewid=".ss($_REQUEST['viewid']); 52: $r=$NATS->DB->Query($q); 53: if ($NATS->DB->Num_Rows($r)<=0) 54: { 55: $ob[]="Invalid View ".$_REQUEST['viewid']; 56: show_output(); 57: } 58: $view=$NATS->DB->Fetch_Array($r); 59: if ($view['vpublic']!=1) // requires auth 60: { 61: if (!$session) 62: { 63: $ob[]="Sorry not a public view"; 64: show_output(); 65: } 66: } 67: 68: if ($view['vcolon']>0) $colon=":"; 69: else $colon=""; 70: if ($view['vdashes']>0) $dash=" -"; 71: else $dash=""; 72: if ($view['vtimeago']>0) $ago=true; 73: else $ago=false; 74: 75: function vdt($dt) 76: { 77: global $ago; 78: if ($ago) return dtago($dt); 79: return nicedt($dt); 80: } 81: 82: function ViewNode($nodeid,$detail=true) 83: { 84: global $NATS; 85: $ret=array(); 86: $q="SELECT * FROM fnnode WHERE nodeid=\"".ss($nodeid)."\""; 87: $r=$NATS->DB->Query($q); 88: if ($NATS->DB->Num_Rows($r)<=0) return $ret; 89: $row=$NATS->DB->Fetch_Array($r); 90: if ($row['nodename']!="") $ret['name']=$row['nodename']; 91: else $ret['name']=$nodeid; 92: $ret['item']=$ret['name']; 93: $ret['nodeid']=$nodeid; 94: $ret['status']=$row['alertlevel']; 95: $ret['link']="node.php?nodeid=".$nodeid; 96: $NATS->DB->Free($r); 97: 98: $ret['detail']=array(); 99: 100: if ($detail) 101: { 102: // get detail 103: $q="SELECT testtype,testparam,testname,alertlevel FROM fnlocaltest WHERE nodeid=\"".ss($nodeid)."\" ORDER BY alertlevel DESC"; 104: $r=$NATS->DB->Query($q); 105: $a=0; 106: while ($row=$NATS->DB->Fetch_Array($r)) 107: { 108: $an=$row['testtype']; 109: if ($row['testparam']!="") $an.=" (".$row['testparam'].")"; 110: if ($row['testname']=="") $nn=$an; // textify! 111: else $nn=$row['testname']; 112: $ret['detail'][$a]['item']=$nn; 113: $ret['detail'][$a]['status']=$row['alertlevel']; 114: $ret['detail'][$a]['link']=$ret['link']; 115: $a++; 116: } 117: $NATS->DB->Free($r); 118: // get detail 119: $q="SELECT testtype,testdesc,testname,alertlevel FROM fnnstest WHERE nodeid=\"".ss($nodeid)."\" AND testenabled=1 ORDER BY alertlevel DESC"; 120: $r=$NATS->DB->Query($q); 121: $a=0; 122: while ($row=$NATS->DB->Fetch_Array($r)) 123: { 124: if ($row['testname']!="") $nn=$row['testname']; 125: else if ($row['testdesc']!="") $nn=$row['testdesc']; 126: else $nn=$row['testtype']; 127: $ret['detail'][$a]['item']=$nn; 128: $ret['detail'][$a]['status']=$row['alertlevel']; 129: $ret['detail'][$a]['link']=$ret['link']; 130: $a++; 131: } 132: $NATS->DB->Free($r); 133: } 134: return $ret; 135: } 136: 137: function ViewGroup($groupid,$detail=true) 138: { 139: global $NATS; 140: $ret=array(); 141: // Get Group Info 142: $ret['status']=$NATS->GroupAlertLevel($groupid); 143: $gq="SELECT * FROM fngroup WHERE groupid=".ss($groupid)." LIMIT 0,1"; 144: $gr=$NATS->DB->Query($gq); 145: $grow=$NATS->DB->Fetch_Array($gr); 146: $NATS->DB->Free($gr); 147: $ret['name']=$grow['groupname']; 148: $ret['desc']=$grow['groupdesc']; 149: $ret['icon']=$grow['groupicon']; 150: $ret['link']="group.php?groupid=".$groupid; 151: 152: // Node Detail 153: if ($detail) 154: { 155: $ret['detail']=array(); 156: $a=0; 157: $lq="SELECT nodeid FROM fngrouplink WHERE groupid=".ss($groupid); 158: $lr=$NATS->DB->Query($lq); 159: while ($link=$NATS->DB->Fetch_Array($lr)) 160: { 161: $nq="SELECT nodename,alertlevel FROM fnnode WHERE nodeid=\"".$link['nodeid']."\" AND nodeenabled=1 ORDER BY alertlevel DESC, weight ASC"; 162: //$nq="SELECT nodename,alertlevel FROM fnnode"; 163: $nq.=" LIMIT 0,1"; 164: $nr=$NATS->DB->Query($nq); 165: $node=$NATS->DB->Fetch_Array($nr); 166: $ret['detail'][$a]['nodeid']=$link['nodeid']; 167: $ret['detail'][$a]['nodename']=$node['nodename']; 168: $ret['detail'][$a]['status']=$node['alertlevel']; 169: $ret['detail'][$a]['link']="node.php?nodeid=".$link['nodeid']; 170: $a++; 171: $NATS->DB->Free($nr); 172: } 173: $NATS->DB->Free($lr); 174: } 175: 176: return $ret; 177: } 178: 179: $q="SELECT * FROM fnviewitem WHERE viewid=".ss($_REQUEST['viewid'])." ORDER BY iweight ASC"; 180: $r=$NATS->DB->Query($q); 181: while ($row=$NATS->DB->Fetch_Array($r)) 182: { 183: $id=$row['viewitemid']; 184: $items[$id]=$row; 185: // get name (varying), status and detail dependent... 186: switch ($row['itype']) 187: { 188: case "node": 189: $items[$id]['data']=ViewNode($row['ioption']); 190: break; 191: 192: case "allnodes": case "alertnodes": 193: $items[$id]['detail']=array(); 194: if ($row['itype']=="allnodes") $q="SELECT nodeid FROM fnnode WHERE nodeenabled=1 ORDER BY `weight` ASC"; 195: else if ($row['itype']=="alertnodes") $q="SELECT nodeid FROM fnnode WHERE nodeenabled=1 AND alertlevel>0 ORDER BY `weight` ASC"; 196: $ret=$NATS->DB->Query($q); 197: //echo "!".$q."
";
198: $a=0; 199: while ($noderow=$NATS->DB->Fetch_Array($ret)) 200: { 201: if ($row['idetail']==1) $det=true; 202: else $det=false; 203: $items[$id]['detail'][$a]['data']=ViewNode($noderow['nodeid'],$det); 204: $items[$id]['detail'][$a]['icolour']=$row['icolour']; 205: $items[$id]['detail'][$a]['idetail']=$row['idetail']; 206: $items[$id]['detail'][$a]['igraphic']=$row['igraphic']; 207: $items[$id]['detail'][$a++]['itextstatus']=$row['itextstatus']; 208: } 209: $NATS->DB->Free($ret); 210: break; 211: 212: case "allgroups": case "alertgroups": 213: $items[$id]['detail']=array(); 214: $q="SELECT groupid FROM fngroup ORDER BY weight ASC"; 215: $ret=$NATS->DB->Query($q); 216: $a=0; 217: while ($grouprow=$NATS->DB->Fetch_Array($ret)) 218: { 219: if ( ($row['itype']=="allgroups") || ($NATS->GroupAlertLevel($grouprow['groupid'])>0) ) 220: { 221: $items[$id]['detail'][$a]['data']=ViewGroup($grouprow['groupid'],$row['idetail']); 222: $items[$id]['detail'][$a]['icolour']=$row['icolour']; 223: $items[$id]['detail'][$a]['ioption']=$grouprow['groupid']; 224: $items[$id]['detail'][$a]['idetail']=$row['idetail']; 225: $items[$id]['detail'][$a]['igraphic']=$row['igraphic']; 226: $items[$id]['detail'][$a++]['itextstatus']=$row['itextstatus']; 227: } 228: } 229: $NATS->DB->Free($ret); 230: break; 231: 232: case "group": 233: $items[$id]['data']=ViewGroup($row['ioption'],$row['idetail']); 234: break; 235: 236: case "testgraph": 237: // can't be arsed to do link here 238: break; 239: 240: case "alerts": 241: $c=0; 242: $alev=0; 243: $items[$id]['detail']=array(); 244: $alq="SELECT nodeid,openedx,alertlevel FROM fnalert WHERE closedx=0"; 245: $alr=$NATS->DB->Query($alq); 246: while ($al=$NATS->DB->Fetch_Array($alr)) 247: { 248: $items[$id]['detail'][$c]['nodeid']=$al['nodeid']; 249: $items[$id]['detail'][$c]['link']="node.php?nodeid=".$al['nodeid']; 250: if ($al['alertlevel']>$alev) $alev=$al['alertlevel']; 251: $items[$id]['detail'][$c]['status']=$al['alertlevel']; 252: $c++; 253: } 254: $items[$id]['data']['status']=$alev; 255: $items[$id]['data']['alerts']=$c; 256: $NATS->DB->Free($alr); 257: break; 258: 259: case "testdetail": 260: // localtest only thus far 261: $tclass=$row['ioption'][0]; 262: //$tid=substr($row['ioption'],1,128); 263: 264: /* 265: $tquery="SELECT * FROM fnlocaltest WHERE localtestid=\"".ss($tid)."\" LIMIT 0,1"; 266: $tres=$NATS->DB->Query($tquery); 267: if ($trow=$NATS->DB->Fetch_Array($tres)) 268: { 269: $items[$id]['status']=$trow['alertlevel']; 270: $items[$id]['lastrunx']=$trow['lastrunx']; 271: $items[$id]['dtago']=dtago($trow['lastrunx']); 272: $items[$id]['vtime']=vdt($trow['lastrunx']); 273: $items[$id]['nodeid']=$trow['nodeid']; 274: } 275: $NATS->DB->Free($tres); 276: */ 277: 278: $test=$NATS->GetTest($row['ioption']); 279: if ($test!==false) 280: { 281: $items[$id]['status']=$test['alertlevel']; 282: $items[$id]['lastrunx']=$test['lastrunx']; 283: $items[$id]['dtago']=dtago($test['lastrunx']); 284: $items[$id]['vtime']=vdt($test['lastrunx']); 285: $items[$id]['nodeid']=$test['nodeid']; 286: } 287: break; 288: 289: } 290: 291: } 292: 293: // begin the buffering of output... 294: 295: // title and header 296: if ($view['vstyle']=="plain") 297: { 298: $ob[]=""; 299: $ob[]=""; 308: $ob[]=""; 309: } 310: else if ($view['vstyle']=="mobile") 311: { 312: $ob[]=""; 313: if ($view['vrefresh']>0) $ob[]=""; 314: $ob[]=""; 323: $ob[]=""; 324: } 325: else // standard and catch-all 326: { 327: $ob[]=""; 328: if ($view['vrefresh']>0) $ob[]=""; 329: $ob[]="FreeNATS: ".$view['vtitle'].""; 330: $ob[]=""; 339: $ob[]=""; 340: $ob[]=""; 341: $ob[]=""; 343: $ob[]="
"; 342: $ob[]="FreeNATS: ".$view['vtitle']."
";
344: $ob[]="
";
345: } 346: 347: // now the items 348: 349: function small_node($item) 350: { 351: global $abs,$view,$colon,$dashes; 352: $ob=array(); // our local copy 353: $uri=$abs.$item['data']['link']; 354: if ($view['vlinkv']!=0) 355: { 356: $uri=$abs."view.php?viewid=".$view['vlinkv']; 357: } 358: $link=$view['vclick']; 359: if ($link=="disabled") $l=""; 360: else if ($link=="standard") $l="";
361: else if ($link=="frametop") $l=""; 362: else if ($link=="newwindow") $l=""; 363: else $l=""; 364: 365: // alert lights only as no fancy full-on tables etc yet 366: if ($item['igraphic']>0) // actually therefore should only be ==1 with 2 being the "proper" one 367: { 368: $is=" "; 369: $ob[]=$is; 370: } 371: 372: $ob[]=$l; 373: 374: if ($item['icolour']==1) $ob[]=""; 375: 376: $out=$item['data']['name']; 377: if ($item['itextstatus']==1) $out.=$colon." ".oText($item['data']['status']); 378: $ob[]=$out.""; 379: 380: if ($item['icolour']==1) $ob[]=""; 381: 382: // detail like tests etc... 383: if ($item['idetail']>0) 384: { 385: $a=0; 386: foreach($item['data']['detail'] as $dline) 387: { 388: $a++; 389: $ob[]="
 - ";
390: if ($item['icolour']==1) $ob[]=""; 391: $out=$dline['item']; 392: if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']); 393: $ob[]=$out; 394: if ($item['icolour']==1) $ob[]=""; 395: } 396: //if ($a>0) $ob[]="
";
397: } 398: 399: return $ob; 400: } 401: 402: function large_node($item) 403: { 404: global $abs,$view,$colon,$dashes; 405: $ob=array(); // our local copy 406: $uri=$abs.$item['data']['link']; 407: if ($view['vlinkv']!=0) 408: { 409: $uri=$abs."view.php?viewid=".$view['vlinkv']; 410: } 411: $link=$view['vclick']; 412: if ($link=="disabled") $l=""; 413: else if ($link=="standard") $l=""; 414: else if ($link=="frametop") $l=""; 415: else if ($link=="newwindow") $l=""; 416: else $l=""; 417: 418: if ($item['icolour']==1) $col=true; 419: else $col=false; 420: 421: if ($col) 422: { 423: switch($item['data']['status']) 424: { 425: case -1: $c="#a0a0a0"; break; 426: case 0: $c="green"; break; 427: case 1: $c="orange"; break; 428: case 2: $c="red"; break; 429: default: $c="black"; break; 430: } 431: } 432: else $c="#a0a0a0"; 433: $ss="width: 250; border: dotted 1px ".$c.";"; 434: 435: $ob[]=""; 436: 437: if ($item['igraphic']==1) 438: { 439: $is=" "; 440: } 441: else if ($item['igraphic']>0) 442: { 443: $is=" "; 444: } 445: else $is=" "; 446: 447: $ob[]=""; 459: // detail like tests etc... 460: if ($item['idetail']>0) 461: { 462: $ob[]=""; 476: //if ($a>0) $ob[]="
";
477: } 478: 479: 480: $ob[]="
"; 448: $ob[]=$l; 449: if ($item['icolour']==1) $ob[]=""; 450: 451: $out=$item['data']['name']; 452: if ($item['itextstatus']==1) $out.=$colon." ".oText($item['data']['status']); 453: $ob[]=$out.""; 454: 455: if ($item['icolour']==1) $ob[]=""; 456: $ob[]=""; 457: $ob[]=$is; 458: $ob[]="
"; 463: $a=0; 464: foreach($item['data']['detail'] as $dline) 465: { 466: $a++; 467: $ob[]=" - "; 468: if ($item['icolour']==1) $ob[]=""; 469: $out=$dline['item']; 470: if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']); 471: $ob[]=$out; 472: if ($item['icolour']==1) $ob[]=""; 473: $ob[]="
";
474: } 475: $ob[]="
";
481: return $ob; 482: } 483: 484: function large_group($item) 485: { 486: global $abs,$view,$colon,$dashes; 487: $ob=array(); // our local copy 488: $uri=$abs.$item['data']['link']; 489: if ($view['vlinkv']!=0) 490: { 491: $uri=$abs."view.php?viewid=".$view['vlinkv']; 492: } 493: $link=$view['vclick']; 494: if ($link=="disabled") $l="
"; 495: else if ($link=="standard") $l=""; 496: else if ($link=="frametop") $l=""; 497: else if ($link=="newwindow") $l=""; 498: else $l=""; 499: 500: if ($item['icolour']==1) $col=true; 501: else $col=false; 502: 503: if ($col) 504: { 505: switch($item['data']['status']) 506: { 507: case -1: $c="#a0a0a0"; break; 508: case 0: $c="green"; break; 509: case 1: $c="orange"; break; 510: case 2: $c="red"; break; 511: default: $c="black"; break; 512: } 513: } 514: else $c="#a0a0a0"; 515: $ss="width: 250; border: dotted 1px ".$c.";"; 516: 517: $ob[]=""; 518: 519: if ($item['igraphic']==1) 520: { 521: $is=" "; 522: } 523: else if ($item['igraphic']>0) 524: { 525: $is=" "; 526: } 527: else $is=" "; 528: 529: $ob[]=""; 541: 542: if ($item['data']['desc']!="") $ob[]=""; 543: 544: // detail like tests etc... 545: if ($item['idetail']>0) 546: { 547: $ob[]=""; 575: //if ($a>0) $ob[]="
";
576: } 577: 578: 579: $ob[]="
"; 530: $ob[]=$l; 531: if ($item['icolour']==1) $ob[]=""; 532: 533: $out=$item['data']['name']; 534: if ($item['itextstatus']==1) $out.=$colon." ".oText($item['data']['status']); 535: $ob[]=$out.""; 536: 537: if ($item['icolour']==1) $ob[]=""; 538: $ob[]=""; 539: $ob[]=$is; 540: $ob[]="
".$item['data']['desc']."
"; 548: $a=0; 549: foreach($item['data']['detail'] as $dline) 550: { 551: $a++; 552: $ob[]=" - "; 553: 554: $uri=$abs.$item['data']['link']; 555: if ($view['vlinkv']!=0) 556: { 557: $uri=$abs."view.php?viewid=".$view['vlinkv']; 558: } 559: $link=$view['vclick']; 560: if ($link=="disabled") $l=""; 561: else if ($link=="standard") $l=""; 562: else if ($link=="frametop") $l=""; 563: else if ($link=="newwindow") $l=""; 564: else $l=""; 565: $ob[]=$l; 566: if ($item['icolour']==1) $ob[]=""; 567: if ($dline['nodename']!="") $out=$dline['nodename']; 568: else $out=$dline['nodeid']; 569: if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']); 570: $ob[]=$out.""; 571: if ($item['icolour']==1) $ob[]=""; 572: $ob[]="
";
573: } 574: $ob[]="
";
580: return $ob; 581: } 582: 583: function small_group($item) 584: { 585: global $abs,$view,$colon,$dashes; 586: $ob=array(); // our local copy 587: $uri=$abs.$item['data']['link']; 588: if ($view['vlinkv']!=0) 589: { 590: $uri=$abs."view.php?viewid=".$view['vlinkv']; 591: } 592: $link=$view['vclick']; 593: if ($link=="disabled") $l="
"; 594: else if ($link=="standard") $l=""; 595: else if ($link=="frametop") $l=""; 596: else if ($link=="newwindow") $l=""; 597: else $l=""; 598: 599: // alert lights only as no fancy full-on tables etc yet 600: if ($item['igraphic']>0) // actually therefore should only be ==1 with 2 being the "proper" one 601: { 602: $is=" "; 603: $ob[]=$is; 604: } 605: 606: $ob[]=$l; 607: 608: if ($item['icolour']==1) $ob[]=""; 609: 610: $out=$item['data']['name']; 611: if ($item['itextstatus']==1) $out.=$colon." ".oText($item['data']['status']); 612: $ob[]=$out.""; 613: 614: if ($item['icolour']==1) $ob[]=""; 615: 616: // detail like tests etc... 617: if ($item['idetail']>0) 618: { 619: $a=0; 620: foreach($item['data']['detail'] as $dline) 621: { 622: $a++; 623: $uri=$abs.$item['data']['link']; 624: if ($view['vlinkv']!=0) 625: { 626: $uri=$abs."view.php?viewid=".$view['vlinkv']; 627: } 628: $link=$view['vclick']; 629: if ($link=="disabled") $l=""; 630: else if ($link=="standard") $l=""; 631: else if ($link=="frametop") $l=""; 632: else if ($link=="newwindow") $l=""; 633: else $l=""; 634: $ob[]="
 - ";
635: $ob[]=$l; 636: if ($item['icolour']==1) $ob[]=""; 637: if ($dline['nodename']=="") $out=$dline['nodeid']; 638: else $out=$dline['nodename']; 639: if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']); 640: $ob[]=$out."
"; 641: if ($item['icolour']==1) $ob[]=""; 642: } 643: //if ($a>0) $ob[]="
";
644: } 645: 646: return $ob; 647: } 648: 649: function small_alerts($item) 650: { 651: global $abs,$view,$colon,$dashes; 652: $ob=array(); // our local copy 653: $uri=$abs."monitor.php"; 654: if ($view['vlinkv']!=0) 655: { 656: $uri=$abs."view.php?viewid=".$view['vlinkv']; 657: } 658: $link=$view['vclick']; 659: if ($link=="disabled") $l=""; 660: else if ($link=="standard") $l=""; 661: else if ($link=="frametop") $l=""; 662: else if ($link=="newwindow") $l=""; 663: else $l=""; 664: 665: // alert lights only as no fancy full-on tables etc yet 666: if ($item['igraphic']>0) // actually therefore should only be ==1 with 2 being the "proper" one 667: { 668: $is=" "; 669: //$ob[]=$is; 670: } 671: 672: $ob[]=$l; 673: 674: if ($item['icolour']==1) $ob[]=""; 675: 676: if ($item['data']['alerts']==0) $out="No System Alerts"; 677: else $out="System Alerts (".$item['data']['alerts'].")"; 678: $ob[]=$out.""; 679: 680: if ($item['icolour']==1) $ob[]=""; 681: 682: // detail like tests etc... 683: if ($item['idetail']>0) 684: { 685: $a=0; 686: if ($item['data']['alerts']==0) 687: { 688: $ob[]="
 - There are no alerts";
689: } 690: else 691: { 692: foreach($item['detail'] as $dline) 693: { 694: $a++; 695: $ob[]="
 - ";
696: $uri=$abs.$dline['link']; 697: if ($view['vlinkv']!=0) 698: { 699: $uri=$abs."view.php?viewid=".$view['vlinkv']; 700: } 701: $link=$view['vclick']; 702: if ($link=="disabled") $l=""; 703: else if ($link=="standard") $l=""; 704: else if ($link=="frametop") $l=""; 705: else if ($link=="newwindow") $l=""; 706: else $l=""; 707: $ob[]=$l; 708: 709: if ($item['icolour']==1) $ob[]=""; 710: $out=$dline['nodeid']; 711: if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']); 712: $ob[]=$out.""; 713: if ($item['icolour']==1) $ob[]=""; 714: } 715: //if ($a>0) $ob[]="
";
716: } 717: } 718: $ob[]="
";
719: 720: return $ob; 721: } 722: 723: 724: function large_alerts($item) 725: { 726: global $abs,$view,$colon,$dashes; 727: $ob=array(); // our local copy 728: $uri=$abs."monitor.php"; 729: if ($view['vlinkv']!=0) 730: { 731: $uri=$abs."view.php?viewid=".$view['vlinkv']; 732: } 733: $link=$view['vclick']; 734: if ($link=="disabled") $l=""; 735: else if ($link=="standard") $l=""; 736: else if ($link=="frametop") $l=""; 737: else if ($link=="newwindow") $l=""; 738: else $l=""; 739: 740: if ($item['icolour']==1) $col=true; 741: else $col=false; 742: 743: if ($col) 744: { 745: switch($item['data']['status']) 746: { 747: case -1: $c="#a0a0a0"; break; 748: case 0: $c="green"; break; 749: case 1: $c="orange"; break; 750: case 2: $c="red"; break; 751: default: $c="black"; break; 752: } 753: } 754: else $c="#a0a0a0"; 755: $ss="width: 250; border: dotted 1px ".$c.";"; 756: 757: $ob[]=""; 758: 759: 760: 761: // alert lights only as no fancy full-on tables etc yet 762: if ($item['igraphic']>0) // actually therefore should only be ==1 with 2 being the "proper" one 763: { 764: $is=" "; 765: //$ob[]=$is; 766: } 767: else $is=" "; 768: 769: $ob[]=""; 782: 783: // detail like tests etc... 784: if ($item['idetail']>0) 785: { 786: $a=0; 787: if ($item['data']['alerts']==0) 788: { 789: $ob[]=""; 790: } 791: else 792: { 793: foreach($item['detail'] as $dline) 794: { 795: $a++; 796: $ob[]=""; 816: } 817: //if ($a>0) $ob[]="
";
818: } 819: } 820: $ob[]="
"; 770: 771: if ($item['icolour']==1) $ob[]=""; 772: 773: if ($item['data']['alerts']==0) $out="No System Alerts"; 774: else $out="System Alerts (".$item['data']['alerts'].")"; 775: $ob[]=$out.""; 776: 777: if ($item['icolour']==1) $ob[]=""; 778: 779: $ob[]=""; 780: $ob[]=$is; 781: $ob[]="
 - There are no alerts
 - "; 797: $uri=$abs.$dline['link']; 798: if ($view['vlinkv']!=0) 799: { 800: $uri=$abs."view.php?viewid=".$view['vlinkv']; 801: } 802: $link=$view['vclick']; 803: if ($link=="disabled") $l=""; 804: else if ($link=="standard") $l=""; 805: else if ($link=="frametop") $l=""; 806: else if ($link=="newwindow") $l=""; 807: else $l=""; 808: $ob[]=$l; 809: 810: if ($item['icolour']==1) $ob[]=""; 811: $out=$dline['nodeid']; 812: if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']); 813: $ob[]=$out.""; 814: if ($item['icolour']==1) $ob[]=""; 815: $ob[]="
";
821: 822: return $ob; 823: 824: 825: 826: } 827: 828: 829: 830: 831: 832: if ($view['vcolumns']>1) 833: { 834: $usecols=true; 835: $colcount=$view['vcolumns']; 836: } 837: else $usecols=false; 838: 839: foreach($items as $item) 840: { 841: switch ($item['itype']) 842: { 843: case "node": 844: if ($item['isize']>0) $output=large_node($item); 845: else $output=small_node($item); 846: foreach($output as $line) $ob[]=$line; 847: 848: break; 849: 850: case "group": 851: if ($item['isize']>0) $output=large_group($item); 852: else $output=small_group($item); 853: foreach($output as $line) $ob[]=$line; 854: break; 855: 856: case "alerts": 857: if ($item['isize']>0) $output=large_alerts($item); 858: else $output=small_alerts($item); 859: foreach($output as $line) $ob[]=$line; 860: break; 861: 862: case "allnodes": case "alertnodes": 863: $c=0; 864: if ($usecols) $ob[]=""; 865: foreach($item['detail'] as $node) 866: { 867: if ($usecols) 868: { 869: if ($c==0) $ob[]=""; 870: $ob[]=""; 879: $c++; 880: if ($c>=$colcount) 881: { 882: $ob[]=""; 883: $ob[]=""; 884: $c=0; 885: } 886: } 887: else $ob[]="
";
888: } 889: if (($usecols) && ($c<3)) $ob[]=""; 890: if ($usecols) $ob[]="
"; 871: } 872: if ($item['isize']==1) $output=large_node($node); 873: else $output=small_node($node); 874: foreach($output as $line) $ob[]=$line; 875: 876: if ($usecols) 877: { 878: $ob[]="
 
";
891: break; 892: 893: case "allgroups": case "alertgroups": 894: $c=0; 895: if ($usecols) $ob[]=""; 896: foreach($item['detail'] as $group) 897: { 898: if ($usecols) 899: { 900: if ($c==0) $ob[]=""; 901: $ob[]=""; 910: $c++; 911: if ($c>=$colcount) 912: { 913: $ob[]=""; 914: $ob[]=""; 915: $c=0; 916: } 917: } 918: else $ob[]="
";
919: } 920: if (($usecols) && ($c<3)) $ob[]=""; 921: if ($usecols) $ob[]="
"; 902: } 903: if ($item['isize']==1) $output=large_group($group); 904: else $output=small_group($group); 905: foreach($output as $line) $ob[]=$line; 906: 907: if ($usecols) 908: { 909: $ob[]="
 
";
922: break; 923: 924: case "title": 925: if ($item['isize']>0) $ob[]=""; 926: else if ($item['icolour']==1) $ob[]=""; 927: $ob[]=$item['ioption']; 928: if ( ($item['isize']>0) || ($item['icolour']==1) ) $ob[]=""; 929: break; 930: 931: case "testdetail": 932: 933: $is=""; 934: if ($item['igraphic']>0) 935: { 936: $is=" "; 937: } 938: 939: if ($is!="") $ob[]=$is; 940: 941: $uri=$abs."node.php?nodeid=".$item['nodeid']; 942: if ($view['vlinkv']!=0) 943: { 944: $uri=$abs."view.php?viewid=".$view['vlinkv']; 945: } 946: $link=$view['vclick']; 947: if ($link=="disabled") $l="
"; 948: else if ($link=="standard") $l=""; 949: else if ($link=="frametop") $l=""; 950: else if ($link=="newwindow") $l=""; 951: else $l=""; 952: $ob[]=$l; 953: 954: if ($item['icolour']==1) $ob[]=""; 955: else $ob[]=""; 956: 957: $s=$item['iname']; 958: if ($item['itextstatus']==1) $s.=$colon." ".oText($item['status']); 959: $s.=""; 960: $ob[]=$s; 961: if ($item['idetail']>0) 962: { 963: if ($item['isize']>0) $ob[]="
 ".$dash." tested ";
964: else $ob[]=$dash." "; 965: $ob[]=$item['vtime']; 966: } 967: $ob[]="
"; 968: 969: break; 970: 971: case "testgraph": 972: $p=strpos($item['ioption'],"/"); 973: if ($p===false) 974: { 975: $hrs=24; 976: $tid=$item['ioption']; 977: } 978: else 979: { 980: $tid=substr($item['ioption'],0,$p); 981: $hrs=substr($item['ioption'],$p+1,20); 982: if ($hrs=="") $hrs=24; 983: } 984: if ($item['isize']>0) 985: { 986: $width=700; 987: $height=150; 988: } 989: else 990: { 991: $width=350; 992: $height=100; 993: } 994: // colours eventually... 995: 996: $uri=$abs."history.test.php?testid=".$tid; 997: if ($view['vlinkv']!=0) 998: { 999: $uri=$abs."view.php?viewid=".$view['vlinkv']; 1000: } 1001: $link=$view['vclick']; 1002: if ($link=="disabled") $l=""; 1003: else if ($link=="standard") $l=""; 1004: else if ($link=="frametop") $l=""; 1005: else if ($link=="newwindow") $l=""; 1006: else $l=""; 1007: 1008: 1009: $i=$abs."test.graph.php?testid=".$tid; 1010: $graphkey=$NATS->Cfg->Get("site.graph.key",""); 1011: if ($graphkey!="") $i.="&graphkey=".$graphkey; 1012: $i.="&startx="; 1013: $now=time(); 1014: $startx=$now-($hrs*60*60); 1015: $i.=$startx."&finishx=".$now."&width=".$width."&height=".$height; 1016: $ob[]=$l.""; 1017: break; 1018: 1019: } 1020: $ob[]="
";
1021: 1022: } 1023: 1024: // footer 1025: if ($view['vstyle']=="mobile") 1026: { 1027: $ob[]=""; 1028: } 1029: else if ($view['vstyle']=="plain") 1030: { 1031: $ob[]=""; 1032: } 1033: else // standard and catch-all 1034: { 1035: $ob[]=""; 1036: $ob[]=""; 1040: $ob[]="
Powered by FreeNATS"; 1037: $ob[]=""; 1038: $ob[]="Login to System"; 1039: $ob[]="
";
1041: } 1042: 1043: 1044: 1045: // finally the output 1046: switch ($mode) 1047: { 1048: case "debug": 1049: echo "
";
1050: 	var_dump($items);
1051: 	echo "

";
1052: foreach($ob as $l) 1053: echo htmlspecialchars($l)."\n"; 1054: break; 1055: 1056: case "js": 1057: //echo "\n"; 1066: echo "\n"; 1067: break; 1068: 1069: default: 1070: foreach($ob as $l) 1071: { 1072: echo $l; 1073: echo "\n"; 1074: } 1075: } 1076: 1077: ?>