File: 0.02.56a/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['status']=$row['alertlevel']; 80: $ret['link']="node.php?nodeid=".$nodeid; 81: $NATS->DB->Free($r); 82: 83: $ret['detail']=array(); 84: 85: if ($detail) 86: { 87: // get detail 88: $q="SELECT testtype,testparam,testname,alertlevel FROM fnlocaltest WHERE nodeid=\"".ss($nodeid)."\" ORDER BY alertlevel DESC"; 89: $r=$NATS->DB->Query($q); 90: $a=0; 91: while ($row=$NATS->DB->Fetch_Array($r)) 92: { 93: $an=$row['testtype']; 94: if ($row['testparam']!="") $an.=" (".$row['testparam'].")"; 95: if ($row['testname']=="") $nn=$an; // textify! 96: else $nn=$row['testname']; 97: $ret['detail'][$a]['item']=$nn; 98: $ret['detail'][$a]['status']=$row['alertlevel']; 99: $ret['detail'][$a]['link']=$ret['link']; 100: $a++; 101: } 102: $NATS->DB->Free($r); 103: } 104: return $ret; 105: } 106: 107: $q="SELECT * FROM fnviewitem WHERE viewid=".ss($_REQUEST['viewid'])." ORDER BY iweight ASC"; 108: $r=$NATS->DB->Query($q); 109: while ($row=$NATS->DB->Fetch_Array($r)) 110: { 111: $id=$row['viewitemid']; 112: $items[$id]=$row; 113: // get name (varying), status and detail dependent... 114: switch ($row['itype']) 115: { 116: case "node": 117: $items[$id]['data']=ViewNode($row['ioption']); 118: break; 119: 120: case "allnodes": case "alertnodes": 121: $items[$id]['detail']=array(); 122: if ($row['itype']=="allnodes") $q="SELECT nodeid FROM fnnode WHERE nodeenabled=1 ORDER BY `weight` ASC"; 123: else if ($row['itype']=="alertnodes") $q="SELECT nodeid FROM fnnode WHERE nodeenabled=1 AND alertlevel>0 ORDER BY `weight` ASC"; 124: $ret=$NATS->DB->Query($q); 125: //echo "!".$q."
";
126: $a=0; 127: while ($noderow=$NATS->DB->Fetch_Array($ret)) 128: { 129: if ($row['idetail']==1) $det=true; 130: else $det=false; 131: $items[$id]['detail'][$a]['data']=ViewNode($noderow['nodeid'],$det); 132: $items[$id]['detail'][$a]['icolour']=$row['icolour']; 133: $items[$id]['detail'][$a]['idetail']=$row['idetail']; 134: $items[$id]['detail'][$a]['igraphic']=$row['igraphic']; 135: $items[$id]['detail'][$a++]['itextstatus']=$row['itextstatus']; 136: } 137: break; 138: } 139: 140: } 141: 142: // begin the buffering of output... 143: 144: // title and header 145: if ($view['vstyle']=="plain") 146: { 147: $ob[]=""; 148: $ob[]=""; 157: $ob[]=""; 158: } 159: else if ($view['vstyle']=="mobile") 160: { 161: $ob[]=""; 162: if ($view['vrefresh']>0) $ob[]=""; 163: $ob[]=""; 172: $ob[]=""; 173: } 174: else // standard and catch-all 175: { 176: $ob[]=""; 177: if ($view['vrefresh']>0) $ob[]=""; 178: $ob[]="FreeNATS: ".$view['vtitle'].""; 179: $ob[]=""; 188: $ob[]=""; 189: $ob[]=""; 190: $ob[]=""; 192: $ob[]="
"; 191: $ob[]="FreeNATS: ".$view['vtitle']."
";
193: } 194: 195: // now the items 196: 197: function small_node($item) 198: { 199: global $abs,$view; 200: $ob=array(); // our local copy 201: $uri=$abs.$item['data']['link']; 202: if ($view['vlinkv']!=0) 203: { 204: $uri=$abs."view.php?viewid=".$view['vlinkv']; 205: } 206: $link=$view['vclick']; 207: if ($link=="disabled") $l=""; 208: else if ($link=="standard") $l="";
209: else if ($link=="frametop") $l=""; 210: else if ($link=="newwindow") $l=""; 211: else $l=""; 212: 213: // alert lights only as no fancy full-on tables etc yet 214: if ($item['igraphic']>0) // actually therefore should only be ==1 with 2 being the "proper" one 215: { 216: $is=" "; 217: $ob[]=$is; 218: } 219: 220: $ob[]=$l; 221: 222: if ($item['icolour']==1) $ob[]=""; 223: 224: $out=$item['data']['name']; 225: if ($item['itextstatus']==1) $out.=": ".oText($item['data']['status']); 226: $ob[]=$out.""; 227: 228: if ($item['icolour']==1) $ob[]=""; 229: 230: // detail like tests etc... 231: if ($item['idetail']>0) 232: { 233: $a=0; 234: foreach($item['data']['detail'] as $dline) 235: { 236: $a++; 237: $ob[]="
 - ";
238: if ($item['icolour']==1) $ob[]=""; 239: $out=$dline['item']; 240: if ($item['itextstatus']==1) $out.=": ".oText($dline['status']); 241: $ob[]=$out; 242: if ($item['icolour']==1) $ob[]=""; 243: } 244: //if ($a>0) $ob[]="
";
245: } 246: 247: return $ob; 248: } 249: 250: foreach($items as $item) 251: { 252: switch ($item['itype']) 253: { 254: case "node": 255: $output=small_node($item); 256: foreach($output as $line) $ob[]=$line; 257: 258: break; 259: 260: case "allnodes": case "alertnodes": 261: foreach($item['detail'] as $node) 262: { 263: $output=small_node($node); 264: foreach($output as $line) $ob[]=$line; 265: $ob[]="
";
266: } 267: break; 268: 269: } 270: $ob[]="
";
271: 272: } 273: 274: // footer 275: $ob[]=""; 276: 277: // finally the output 278: switch ($mode) 279: { 280: case "debug": 281: echo "
";
282: 	var_dump($items);
283: 	echo "

";
284: foreach($ob as $l) 285: echo htmlspecialchars($l)."\n"; 286: break; 287: 288: case "js": 289: //echo "\n"; 298: echo "\n"; 299: break; 300: 301: default: 302: foreach($ob as $l) 303: { 304: echo $l; 305: echo "\n"; 306: } 307: } 308: 309: ?>