File: 0.02.58a/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: function ViewNode($nodeid,$detail=true) 69: { 70: global $NATS; 71: $ret=array(); 72: $q="SELECT * FROM fnnode WHERE nodeid=\"".ss($nodeid)."\""; 73: $r=$NATS->DB->Query($q); 74: if ($NATS->DB->Num_Rows($r)<=0) return $ret; 75: $row=$NATS->DB->Fetch_Array($r); 76: if ($row['nodename']!="") $ret['name']=$row['nodename']; 77: else $ret['name']=$nodeid; 78: $ret['item']=$ret['name']; 79: $ret['nodeid']=$nodeid; 80: $ret['status']=$row['alertlevel']; 81: $ret['link']="node.php?nodeid=".$nodeid; 82: $NATS->DB->Free($r); 83: 84: $ret['detail']=array(); 85: 86: if ($detail) 87: { 88: // get detail 89: $q="SELECT testtype,testparam,testname,alertlevel FROM fnlocaltest WHERE nodeid=\"".ss($nodeid)."\" ORDER BY alertlevel DESC"; 90: $r=$NATS->DB->Query($q); 91: $a=0; 92: while ($row=$NATS->DB->Fetch_Array($r)) 93: { 94: $an=$row['testtype']; 95: if ($row['testparam']!="") $an.=" (".$row['testparam'].")"; 96: if ($row['testname']=="") $nn=$an; // textify! 97: else $nn=$row['testname']; 98: $ret['detail'][$a]['item']=$nn; 99: $ret['detail'][$a]['status']=$row['alertlevel']; 100: $ret['detail'][$a]['link']=$ret['link']; 101: $a++; 102: } 103: $NATS->DB->Free($r); 104: } 105: return $ret; 106: } 107: 108: $q="SELECT * FROM fnviewitem WHERE viewid=".ss($_REQUEST['viewid'])." ORDER BY iweight ASC"; 109: $r=$NATS->DB->Query($q); 110: while ($row=$NATS->DB->Fetch_Array($r)) 111: { 112: $id=$row['viewitemid']; 113: $items[$id]=$row; 114: // get name (varying), status and detail dependent... 115: switch ($row['itype']) 116: { 117: case "node": 118: $items[$id]['data']=ViewNode($row['ioption']); 119: break; 120: 121: case "allnodes": case "alertnodes": 122: $items[$id]['detail']=array(); 123: if ($row['itype']=="allnodes") $q="SELECT nodeid FROM fnnode WHERE nodeenabled=1 ORDER BY `weight` ASC"; 124: else if ($row['itype']=="alertnodes") $q="SELECT nodeid FROM fnnode WHERE nodeenabled=1 AND alertlevel>0 ORDER BY `weight` ASC"; 125: $ret=$NATS->DB->Query($q); 126: //echo "!".$q."
";
127: $a=0; 128: while ($noderow=$NATS->DB->Fetch_Array($ret)) 129: { 130: if ($row['idetail']==1) $det=true; 131: else $det=false; 132: $items[$id]['detail'][$a]['data']=ViewNode($noderow['nodeid'],$det); 133: $items[$id]['detail'][$a]['icolour']=$row['icolour']; 134: $items[$id]['detail'][$a]['idetail']=$row['idetail']; 135: $items[$id]['detail'][$a]['igraphic']=$row['igraphic']; 136: $items[$id]['detail'][$a++]['itextstatus']=$row['itextstatus']; 137: } 138: break; 139: } 140: 141: } 142: 143: // begin the buffering of output... 144: 145: // title and header 146: if ($view['vstyle']=="plain") 147: { 148: $ob[]=""; 149: $ob[]=""; 158: $ob[]=""; 159: } 160: else if ($view['vstyle']=="mobile") 161: { 162: $ob[]=""; 163: if ($view['vrefresh']>0) $ob[]=""; 164: $ob[]=""; 173: $ob[]=""; 174: } 175: else // standard and catch-all 176: { 177: $ob[]=""; 178: if ($view['vrefresh']>0) $ob[]=""; 179: $ob[]="FreeNATS: ".$view['vtitle'].""; 180: $ob[]=""; 189: $ob[]=""; 190: $ob[]=""; 191: $ob[]=""; 193: $ob[]="
"; 192: $ob[]="FreeNATS: ".$view['vtitle']."
";
194: $ob[]="
";
195: } 196: 197: // now the items 198: 199: function small_node($item) 200: { 201: global $abs,$view; 202: $ob=array(); // our local copy 203: $uri=$abs.$item['data']['link']; 204: if ($view['vlinkv']!=0) 205: { 206: $uri=$abs."view.php?viewid=".$view['vlinkv']; 207: } 208: $link=$view['vclick']; 209: if ($link=="disabled") $l=""; 210: else if ($link=="standard") $l="";
211: else if ($link=="frametop") $l=""; 212: else if ($link=="newwindow") $l=""; 213: else $l=""; 214: 215: // alert lights only as no fancy full-on tables etc yet 216: if ($item['igraphic']>0) // actually therefore should only be ==1 with 2 being the "proper" one 217: { 218: $is=" "; 219: $ob[]=$is; 220: } 221: 222: $ob[]=$l; 223: 224: if ($item['icolour']==1) $ob[]=""; 225: 226: $out=$item['data']['name']; 227: if ($item['itextstatus']==1) $out.=": ".oText($item['data']['status']); 228: $ob[]=$out.""; 229: 230: if ($item['icolour']==1) $ob[]=""; 231: 232: // detail like tests etc... 233: if ($item['idetail']>0) 234: { 235: $a=0; 236: foreach($item['data']['detail'] as $dline) 237: { 238: $a++; 239: $ob[]="
 - ";
240: if ($item['icolour']==1) $ob[]=""; 241: $out=$dline['item']; 242: if ($item['itextstatus']==1) $out.=": ".oText($dline['status']); 243: $ob[]=$out; 244: if ($item['icolour']==1) $ob[]=""; 245: } 246: //if ($a>0) $ob[]="
";
247: } 248: 249: return $ob; 250: } 251: 252: function large_node($item) 253: { 254: global $abs,$view; 255: $ob=array(); // our local copy 256: $uri=$abs.$item['data']['link']; 257: if ($view['vlinkv']!=0) 258: { 259: $uri=$abs."view.php?viewid=".$view['vlinkv']; 260: } 261: $link=$view['vclick']; 262: if ($link=="disabled") $l=""; 263: else if ($link=="standard") $l=""; 264: else if ($link=="frametop") $l=""; 265: else if ($link=="newwindow") $l=""; 266: else $l=""; 267: 268: if ($item['icolour']==1) $col=true; 269: else $col=false; 270: 271: if ($col) 272: { 273: switch($item['data']['status']) 274: { 275: case -1: $c="#a0a0a0"; break; 276: case 0: $c="green"; break; 277: case 1: $c="orange"; break; 278: case 2: $c="red"; break; 279: default: $c="black"; break; 280: } 281: } 282: else $c="#a0a0a0"; 283: $ss="width: 250; border: dotted 1px ".$c.";"; 284: 285: $ob[]=""; 286: 287: if ($item['igraphic']==1) 288: { 289: $is=" "; 290: } 291: else if ($item['igraphic']>0) 292: { 293: $is=" "; 294: } 295: else $is=" "; 296: 297: $ob[]=""; 309: // detail like tests etc... 310: if ($item['idetail']>0) 311: { 312: $ob[]=""; 326: //if ($a>0) $ob[]="
";
327: } 328: 329: 330: $ob[]="
"; 298: $ob[]=$l; 299: if ($item['icolour']==1) $ob[]=""; 300: 301: $out=$item['data']['name']; 302: if ($item['itextstatus']==1) $out.=": ".oText($item['data']['status']); 303: $ob[]=$out.""; 304: 305: if ($item['icolour']==1) $ob[]=""; 306: $ob[]=""; 307: $ob[]=$is; 308: $ob[]="
"; 313: $a=0; 314: foreach($item['data']['detail'] as $dline) 315: { 316: $a++; 317: $ob[]=" - "; 318: if ($item['icolour']==1) $ob[]=""; 319: $out=$dline['item']; 320: if ($item['itextstatus']==1) $out.=": ".oText($dline['status']); 321: $ob[]=$out; 322: if ($item['icolour']==1) $ob[]=""; 323: $ob[]="
";
324: } 325: $ob[]="
";
331: return $ob; 332: } 333: 334: if ($view['vcolumns']>1) 335: { 336: $usecols=true; 337: $colcount=$view['vcolumns']; 338: } 339: else $usecols=false; 340: 341: foreach($items as $item) 342: { 343: switch ($item['itype']) 344: { 345: case "node": 346: $output=small_node($item); 347: foreach($output as $line) $ob[]=$line; 348: 349: break; 350: 351: case "allnodes": case "alertnodes": 352: $c=0; 353: if ($usecols) $ob[]=""; 354: foreach($item['detail'] as $node) 355: { 356: if ($usecols) 357: { 358: if ($c==0) $ob[]=""; 359: $ob[]=""; 368: $c++; 369: if ($c>=$colcount) 370: { 371: $ob[]=""; 372: $ob[]=""; 373: $c=0; 374: } 375: } 376: else $ob[]="
";
377: } 378: if (($usecols) && ($c<3)) $ob[]=""; 379: if ($usecols) echo "
"; 360: } 361: if ($item['isize']==1) $output=large_node($node); 362: else $output=small_node($node); 363: foreach($output as $line) $ob[]=$line; 364: 365: if ($usecols) 366: { 367: $ob[]="
 
";
380: break; 381: 382: } 383: $ob[]="
";
384: 385: } 386: 387: // footer 388: if ($view['vstyle']=="mobile") 389: { 390: $ob[]=""; 391: } 392: else if ($view['vstyle']=="plain") 393: { 394: $ob[]=""; 395: } 396: else // standard and catch-all 397: { 398: $ob[]=""; 399: $ob[]=""; 403: $ob[]="
Powered by FreeNATS"; 400: $ob[]=""; 401: $ob[]="Login to System"; 402: $ob[]="
";
404: } 405: 406: 407: 408: // finally the output 409: switch ($mode) 410: { 411: case "debug": 412: echo "
";
413: 	var_dump($items);
414: 	echo "

";
415: foreach($ob as $l) 416: echo htmlspecialchars($l)."\n"; 417: break; 418: 419: case "js": 420: //echo "\n"; 429: echo "\n"; 430: break; 431: 432: default: 433: foreach($ob as $l) 434: { 435: echo $l; 436: echo "\n"; 437: } 438: } 439: 440: ?>