Viewing File server/web/view.php of 0.02.56a
|
1: <?php 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."<br>"; 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."<br>"; 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[]="<html><head>"; 148: $ob[]="<style type=\"text/css\">"; 149: $fp=@fopen("css/mini.css","r"); 150: if ($fp) 151: { 152: while(!@feof($fp)) 153: $ob[]=@fgets($fp,1024); 154: } 155: @fclose($fp); 156: $ob[]="</style>"; 157: $ob[]="</head><body>"; 158: } 159: else if ($view['vstyle']=="mobile") 160: { 161: $ob[]="<html><head>"; 162: if ($view['vrefresh']>0) $ob[]="<meta http-equiv=\"refresh\" content=\"".$view['vrefresh']."\">"; 163: $ob[]="<style type=\"text/css\">"; 164: $fp=@fopen("css/mobile.css","r"); 165: if ($fp) 166: { 167: while(!@feof($fp)) 168: $ob[]=@fgets($fp,1024); 169: } 170: @fclose($fp); 171: $ob[]="</style>"; 172: $ob[]="</head><body>"; 173: } 174: else // standard and catch-all 175: { 176: $ob[]="<html><head>"; 177: if ($view['vrefresh']>0) $ob[]="<meta http-equiv=\"refresh\" content=\"".$view['vrefresh']."\">"; 178: $ob[]="<title>FreeNATS: ".$view['vtitle']."</title>"; 179: $ob[]="<style type=\"text/css\">"; 180: $fp=@fopen("css/main.css","r"); 181: if ($fp>0) 182: { 183: while(!@feof($fp)) 184: $ob[]=@fgets($fp,1024); 185: } 186: @fclose($fp); 187: $ob[]="</style>"; 188: $ob[]="</head><body>"; 189: $ob[]="<table width=100% class=\"maintitle\">"; 190: $ob[]="<tr><td align=left valign=center>"; 191: $ob[]="<b class=\"maintitle\">FreeNATS: ".$view['vtitle']."</b></td>"; 192: $ob[]="</tr></table>"; 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="<a href=#>"; 208: else if ($link=="standard") $l="<a href=\"".$uri."\">"; 209: else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>"; 210: else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>"; 211: else $l="<a href=#>"; 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="<img src=\"".$abs."images/lights/a".$item['data']['status'].".png\"> "; 217: $ob[]=$is; 218: } 219: 220: $ob[]=$l; 221: 222: if ($item['icolour']==1) $ob[]="<b class=\"al".$item['data']['status']."\">"; 223: 224: $out=$item['data']['name']; 225: if ($item['itextstatus']==1) $out.=": ".oText($item['data']['status']); 226: $ob[]=$out."</a>"; 227: 228: if ($item['icolour']==1) $ob[]="</b>"; 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[]="<br> - "; 238: if ($item['icolour']==1) $ob[]="<b class=\"al".$dline['status']."\">"; 239: $out=$dline['item']; 240: if ($item['itextstatus']==1) $out.=": ".oText($dline['status']); 241: $ob[]=$out; 242: if ($item['icolour']==1) $ob[]="</b>"; 243: } 244: //if ($a>0) $ob[]="<br>"; 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[]="<br>"; 266: } 267: break; 268: 269: } 270: $ob[]="<br>"; 271: 272: } 273: 274: // footer 275: $ob[]="</html>"; 276: 277: // finally the output 278: switch ($mode) 279: { 280: case "debug": 281: echo "<pre>"; 282: var_dump($items); 283: echo "<br><br>"; 284: foreach($ob as $l) 285: echo htmlspecialchars($l)."\n"; 286: break; 287: 288: case "js": 289: //echo "<script type=\"text/javascript\">\n"; 290: //echo "document.write(\"hello world\");\n"; 291: foreach($ob as $l) 292: { 293: //if ($l[strlen($l)-1]=='\n') $l=substr($l,0,strlen($l)-1); 294: $l=trim($l); 295: echo "document.write(\"".addslashes($l)."\");\n"; 296: } 297: //echo "</script>\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: ?>