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[]="
";
191: $ob[]="FreeNATS: ".$view['vtitle']."
";
192: $ob[]="
";
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: $link=$view['vclick'];
203: if ($link=="disabled") $l="";
204: else if ($link=="standard") $l="";
205: else if ($link=="frametop") $l="";
206: else if ($link=="newwindow") $l="";
207: else $l="";
208:
209: // alert lights only as no fancy full-on tables etc yet
210: if ($item['igraphic']>0) // actually therefore should only be ==1 with 2 being the "proper" one
211: {
212: $is=" ";
213: $ob[]=$is;
214: }
215:
216: $ob[]=$l;
217:
218: if ($item['icolour']==1) $ob[]="";
219:
220: $out=$item['data']['name'];
221: if ($item['itextstatus']==1) $out.=": ".oText($item['data']['status']);
222: $ob[]=$out."";
223:
224: if ($item['icolour']==1) $ob[]="";
225:
226: // detail like tests etc...
227: if ($item['idetail']>0)
228: {
229: $a=0;
230: foreach($item['data']['detail'] as $dline)
231: {
232: $a++;
233: $ob[]=" - ";
234: if ($item['icolour']==1) $ob[]="";
235: $out=$dline['item'];
236: if ($item['itextstatus']==1) $out.=": ".oText($dline['status']);
237: $ob[]=$out;
238: if ($item['icolour']==1) $ob[]="";
239: }
240: //if ($a>0) $ob[]=" ";
241: }
242:
243: return $ob;
244: }
245:
246: foreach($items as $item)
247: {
248: switch ($item['itype'])
249: {
250: case "node":
251: $output=small_node($item);
252: foreach($output as $line) $ob[]=$line;
253:
254: break;
255:
256: case "allnodes": case "alertnodes":
257: foreach($item['detail'] as $node)
258: {
259: $output=small_node($node);
260: foreach($output as $line) $ob[]=$line;
261: $ob[]=" ";
262: }
263: break;
264:
265: }
266: $ob[]=" ";
267:
268: }
269:
270: // footer
271: $ob[]="";
272:
273: // finally the output
274: switch ($mode)
275: {
276: case "debug":
277: echo "