File: 1.09.4a/server/web/view.php (View as HTML)

  1: <?php
  2: /* -------------------------------------------------------------
  3: This file is part of FreeNATS
  4: 
  5: FreeNATS is (C) Copyright 2008-2010 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: 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."<br>";
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[]="<html><head>";
299: 	$ob[]="<style type=\"text/css\">";
300: 	$fp=@fopen("css/mini.css","r");
301: 	if ($fp)
302: 		{
303: 		while(!@feof($fp))
304: 			$ob[]=@fgets($fp,1024);
305: 		}
306: 	@fclose($fp);
307: 	$ob[]="</style>";
308: 	$ob[]="</head><body>";
309: 	}
310: else if ($view['vstyle']=="mobile")
311: 	{
312: 	$ob[]="<html><head>";
313: 	if ($view['vrefresh']>0) $ob[]="<meta http-equiv=\"refresh\" content=\"".$view['vrefresh']."\">";
314: 	$ob[]="<style type=\"text/css\">";
315: 	$fp=@fopen("css/mobile.css","r");
316: 	if ($fp)
317: 		{
318: 		while(!@feof($fp))
319: 			$ob[]=@fgets($fp,1024);
320: 		}
321: 	@fclose($fp);
322: 	$ob[]="</style>";
323: 	$ob[]="</head><body>";
324: 	}
325: else // standard and catch-all
326: 	{
327: 	$ob[]="<html><head>";
328: 	if ($view['vrefresh']>0) $ob[]="<meta http-equiv=\"refresh\" content=\"".$view['vrefresh']."\">";
329: 	$ob[]="<title>FreeNATS: ".$view['vtitle']."</title>";
330: 	$ob[]="<style type=\"text/css\">";
331: 	$fp=@fopen("css/main.css","r");
332: 	if ($fp>0)
333: 		{
334: 		while(!@feof($fp))
335: 			$ob[]=@fgets($fp,1024);
336: 		}
337: 	@fclose($fp);
338: 	$ob[]="</style>";
339: 	$ob[]="</head><body>";
340: 	$ob[]="<table width=100% class=\"maintitle\">";
341: 	$ob[]="<tr><td align=left valign=center>";
342: 	$ob[]="<b class=\"maintitle\">FreeNATS: ".$view['vtitle']."</b></td>";
343: 	$ob[]="</tr></table>";
344: 	$ob[]="<br>";
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="<a href=#>";
360: else if ($link=="standard") $l="<a href=\"".$uri."\">";
361: else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
362: else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
363: else $l="<a href=#>";
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="<img src=\"".$abs."images/lights/a".$item['data']['status'].".png\">&nbsp;";
369: 	$ob[]=$is;
370: 	}
371: 			
372: $ob[]=$l;
373: 			
374: if ($item['icolour']==1) $ob[]="<b class=\"al".$item['data']['status']."\">";
375: 			
376: $out=$item['data']['name'];
377: if ($item['itextstatus']==1) $out.=$colon." ".oText($item['data']['status']);
378: $ob[]=$out."</a>";
379: 	
380: if ($item['icolour']==1) $ob[]="</b>";
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[]="<br>&nbsp;-&nbsp;";
390: 		if ($item['icolour']==1) $ob[]="<b class=\"al".$dline['status']."\">";
391: 		$out=$dline['item'];
392: 		if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']);
393: 		$ob[]=$out;
394: 		if ($item['icolour']==1) $ob[]="</b>";
395: 		}
396: 	//if ($a>0) $ob[]="<br>";
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="<a href=#>";
413: else if ($link=="standard") $l="<a href=\"".$uri."\">";
414: else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
415: else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
416: else $l="<a href=#>";
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[]="<table style=\"".$ss."\">";
436: 
437: if ($item['igraphic']==1)
438: 	{
439: 	$is="<img src=\"".$abs."images/lights/a".$item['data']['status'].".png\">&nbsp;";
440: 	}			
441: else if ($item['igraphic']>0)
442: 	{
443: 	$is="<img src=\"".$abs."icons/".NodeIcon($item['data']['nodeid'])."\">&nbsp;";
444: 	}
445: else $is="&nbsp;";
446: 
447: $ob[]="<tr><td align=left valign=center>";
448: $ob[]=$l;
449: if ($item['icolour']==1) $ob[]="<b class=\"al".$item['data']['status']."\">";
450: 			
451: $out=$item['data']['name'];
452: if ($item['itextstatus']==1) $out.=$colon." ".oText($item['data']['status']);
453: $ob[]=$out."</a>";
454: 	
455: if ($item['icolour']==1) $ob[]="</b>";
456: $ob[]="</td><td align=right valign=center>";
457: $ob[]=$is;
458: $ob[]="</td></tr>";
459: // detail like tests etc...
460: if ($item['idetail']>0)
461: 	{
462: 	$ob[]="<tr><td colspan=2 align=left valign=top>";
463: 	$a=0;
464: 	foreach($item['data']['detail'] as $dline)
465: 		{
466: 		$a++;
467: 		$ob[]="&nbsp;-&nbsp;";
468: 		if ($item['icolour']==1) $ob[]="<b class=\"al".$dline['status']."\">";
469: 		$out=$dline['item'];
470: 		if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']);
471: 		$ob[]=$out;
472: 		if ($item['icolour']==1) $ob[]="</b>";
473: 		$ob[]="<br>";
474: 		}
475: 	$ob[]="</td></tr>";
476: 	//if ($a>0) $ob[]="<br>";
477: 	}
478: 
479: 	
480: $ob[]="</table>";
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="<a href=#>";
495: 	else if ($link=="standard") $l="<a href=\"".$uri."\">";
496: 	else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
497: 	else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
498: 	else $l="<a href=#>";
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[]="<table style=\"".$ss."\">";
518: 	
519: 	if ($item['igraphic']==1)
520: 		{
521: 		$is="<img src=\"".$abs."images/lights/a".$item['data']['status'].".png\">&nbsp;";
522: 		}			
523: 	else if ($item['igraphic']>0)
524: 		{
525: 		$is="<img src=\"".$abs."icons/".GroupIcon($item['ioption'])."\">&nbsp;";
526: 		}
527: 	else $is="&nbsp;";
528: 	
529: 	$ob[]="<tr><td align=left valign=center>";
530: 	$ob[]=$l;
531: 	if ($item['icolour']==1) $ob[]="<b class=\"al".$item['data']['status']."\">";
532: 				
533: 	$out=$item['data']['name'];
534: 	if ($item['itextstatus']==1) $out.=$colon." ".oText($item['data']['status']);
535: 	$ob[]=$out."</a>";
536: 		
537: 	if ($item['icolour']==1) $ob[]="</b>";
538: 	$ob[]="</td><td align=right valign=center>";
539: 	$ob[]=$is;
540: 	$ob[]="</td></tr>";
541: 	
542: 	if ($item['data']['desc']!="") $ob[]="<tr><td colspan=2><i>".$item['data']['desc']."</i></td></tr>";
543: 	
544: 	// detail like tests etc...
545: 	if ($item['idetail']>0)
546: 		{
547: 		$ob[]="<tr><td colspan=2 align=left valign=top>";
548: 		$a=0;
549: 		foreach($item['data']['detail'] as $dline)
550: 			{
551: 			$a++;
552: 			$ob[]="&nbsp;-&nbsp;";
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="<a href=#>";
561: 			else if ($link=="standard") $l="<a href=\"".$uri."\">";
562: 			else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
563: 			else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
564: 			else $l="<a href=#>";
565: 			$ob[]=$l;
566: 			if ($item['icolour']==1) $ob[]="<b class=\"al".$dline['status']."\">";
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."</a>";
571: 			if ($item['icolour']==1) $ob[]="</b>";
572: 			$ob[]="<br>";
573: 			}
574: 		$ob[]="</td></tr>";
575: 		//if ($a>0) $ob[]="<br>";
576: 		}
577: 	
578: 		
579: 	$ob[]="</table>";
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="<a href=#>";
594: 	else if ($link=="standard") $l="<a href=\"".$uri."\">";
595: 	else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
596: 	else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
597: 	else $l="<a href=#>";
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="<img src=\"".$abs."images/lights/a".$item['data']['status'].".png\">&nbsp;";
603: 		$ob[]=$is;
604: 		}
605: 				
606: 	$ob[]=$l;
607: 				
608: 	if ($item['icolour']==1) $ob[]="<b class=\"al".$item['data']['status']."\">";
609: 				
610: 	$out=$item['data']['name'];
611: 	if ($item['itextstatus']==1) $out.=$colon." ".oText($item['data']['status']);
612: 	$ob[]=$out."</a>";
613: 		
614: 	if ($item['icolour']==1) $ob[]="</b>";
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="<a href=#>";
630: 			else if ($link=="standard") $l="<a href=\"".$uri."\">";
631: 			else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
632: 			else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
633: 			else $l="<a href=#>";
634: 			$ob[]="<br>&nbsp;-&nbsp;";
635: 			$ob[]=$l;
636: 			if ($item['icolour']==1) $ob[]="<b class=\"al".$dline['status']."\">";
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."</a>";
641: 			if ($item['icolour']==1) $ob[]="</b>";
642: 			}
643: 		//if ($a>0) $ob[]="<br>";
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="<a href=#>";
660: 	else if ($link=="standard") $l="<a href=\"".$uri."\">";
661: 	else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
662: 	else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
663: 	else $l="<a href=#>";
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="<img src=\"".$abs."images/lights/a".$item['data']['status'].".png\">&nbsp;";
669: 		//$ob[]=$is;
670: 		}
671: 				
672: 	$ob[]=$l;
673: 				
674: 	if ($item['icolour']==1) $ob[]="<b class=\"al".$item['data']['status']."\">";
675: 				
676: 	if ($item['data']['alerts']==0) $out="No System Alerts";
677: 	else $out="System Alerts (".$item['data']['alerts'].")";
678: 	$ob[]=$out."</a>";
679: 		
680: 	if ($item['icolour']==1) $ob[]="</b>";
681: 	
682: 	// detail like tests etc...
683: 	if ($item['idetail']>0)
684: 		{
685: 		$a=0;
686: 		if ($item['data']['alerts']==0)
687: 			{
688: 			$ob[]="<br>&nbsp;-&nbsp;<i>There are no alerts</i>";
689: 			}
690: 		else
691: 			{
692: 			foreach($item['detail'] as $dline)
693: 				{
694: 				$a++;
695: 				$ob[]="<br>&nbsp;-&nbsp;";
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="<a href=#>";
703: 				else if ($link=="standard") $l="<a href=\"".$uri."\">";
704: 				else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
705: 				else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
706: 				else $l="<a href=#>";
707: 				$ob[]=$l;	
708: 
709: 				if ($item['icolour']==1) $ob[]="<b class=\"al".$dline['status']."\">";
710: 				$out=$dline['nodeid'];
711: 				if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']);
712: 				$ob[]=$out."</a>";
713: 				if ($item['icolour']==1) $ob[]="</b>";
714: 				}
715: 			//if ($a>0) $ob[]="<br>";
716: 			}
717: 		}
718: 	$ob[]="<br>";
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="<a href=#>";
735: 	else if ($link=="standard") $l="<a href=\"".$uri."\">";
736: 	else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
737: 	else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
738: 	else $l="<a href=#>";
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[]="<table style=\"".$ss."\">";
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="<img src=\"".$abs."images/lights/a".$item['data']['status'].".png\">&nbsp;";
765: 		//$ob[]=$is;
766: 		}
767: 	else $is="&nbsp;";		
768: 	
769: 	$ob[]="<tr><td align=left valign=center>";
770: 				
771: 	if ($item['icolour']==1) $ob[]="<b class=\"al".$item['data']['status']."\">";
772: 				
773: 	if ($item['data']['alerts']==0) $out="No System Alerts";
774: 	else $out="System Alerts (".$item['data']['alerts'].")";
775: 	$ob[]=$out."</a>";
776: 		
777: 	if ($item['icolour']==1) $ob[]="</b>";
778: 	
779: 	$ob[]="</td><td align=right valign=center>";
780: 	$ob[]=$is;
781: 	$ob[]="</td></tr>";
782: 	
783: 	// detail like tests etc...
784: 	if ($item['idetail']>0)
785: 		{
786: 		$a=0;
787: 		if ($item['data']['alerts']==0)
788: 			{
789: 			$ob[]="<tr><td colspan=2 align=left>&nbsp;-&nbsp;<i>There are no alerts</i></td></tr>";
790: 			}
791: 		else
792: 			{
793: 			foreach($item['detail'] as $dline)
794: 				{
795: 				$a++;
796: 				$ob[]="<tr><td colspan=2>&nbsp;-&nbsp;";
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="<a href=#>";
804: 				else if ($link=="standard") $l="<a href=\"".$uri."\">";
805: 				else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
806: 				else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
807: 				else $l="<a href=#>";
808: 				$ob[]=$l;	
809: 
810: 				if ($item['icolour']==1) $ob[]="<b class=\"al".$dline['status']."\">";
811: 				$out=$dline['nodeid'];
812: 				if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']);
813: 				$ob[]=$out."</a>";
814: 				if ($item['icolour']==1) $ob[]="</b>";
815: 				$ob[]="</td></tr>";
816: 				}
817: 			//if ($a>0) $ob[]="<br>";
818: 			}
819: 		}
820: 	$ob[]="</table>";
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[]="<table border=0>";
865: 			foreach($item['detail'] as $node)
866: 				{
867: 				if ($usecols)
868: 					{
869: 					if ($c==0) $ob[]="<tr>";
870: 					$ob[]="<td align=left valign=top>";
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[]="</td>";
879: 					$c++;
880: 					if ($c>=$colcount)
881: 						{
882: 						$ob[]="</tr>";
883: 						$ob[]="<tr><td colspan=".$colcount.">&nbsp;</td></tr>";
884: 						$c=0;
885: 						}
886: 					}
887: 				else $ob[]="<br>";
888: 				}
889: 			if (($usecols) && ($c<3)) $ob[]="</tr>";
890: 			if ($usecols) $ob[]="</table>";
891: 			break;
892: 			
893: 		case "allgroups": case "alertgroups":
894: 			$c=0;
895: 			if ($usecols) $ob[]="<table border=0>";
896: 			foreach($item['detail'] as $group)
897: 				{
898: 				if ($usecols)
899: 					{
900: 					if ($c==0) $ob[]="<tr>";
901: 					$ob[]="<td align=left valign=top>";
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[]="</td>";
910: 					$c++;
911: 					if ($c>=$colcount)
912: 						{
913: 						$ob[]="</tr>";
914: 						$ob[]="<tr><td colspan=".$colcount.">&nbsp;</td></tr>";
915: 						$c=0;
916: 						}
917: 					}
918: 				else $ob[]="<br>";
919: 				}
920: 			if (($usecols) && ($c<3)) $ob[]="</tr>";
921: 			if ($usecols) $ob[]="</table>";
922: 			break;
923: 			
924: 		case "title":
925: 			if ($item['isize']>0) $ob[]="<b style=\"font-size: 14pt;\">";
926: 			else if ($item['icolour']==1) $ob[]="<b>";
927: 			$ob[]=$item['ioption'];
928: 			if ( ($item['isize']>0) || ($item['icolour']==1) ) $ob[]="</b>";
929: 			break;
930: 			
931: 		case "testdetail":
932: 		
933: 			$is="";
934: 			if ($item['igraphic']>0)
935: 				{
936: 				$is="<img src=\"".$abs."images/lights/a".$item['status'].".png\">&nbsp;";
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="<a href=#>";
948: 			else if ($link=="standard") $l="<a href=\"".$uri."\">";
949: 			else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
950: 			else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
951: 			else $l="<a href=#>";
952: 			$ob[]=$l;
953: 			
954: 			if ($item['icolour']==1) $ob[]="<b class=\"al".$item['status']."\">";
955: 			else $ob[]="<b>";
956: 			
957: 			$s=$item['iname'];
958: 			if ($item['itextstatus']==1) $s.=$colon." ".oText($item['status']);
959: 			$s.="</a>";
960: 			$ob[]=$s;
961: 			if ($item['idetail']>0)
962: 				{
963: 				if ($item['isize']>0) $ob[]="<br>&nbsp;".$dash."&nbsp;tested ";
964: 				else $ob[]=$dash." ";
965: 				$ob[]=$item['vtime'];
966: 				}
967: 			$ob[]="</b>";
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="<a href=#>";
1003: 			else if ($link=="standard") $l="<a href=\"".$uri."\">";
1004: 			else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
1005: 			else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
1006: 			else $l="<a href=#>";
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."<img src=\"".$i."\" border=0></a>";
1017: 			break;
1018: 			
1019: 		}
1020: 		$ob[]="<br>";
1021: 		
1022: 	}
1023: 	
1024: // footer
1025: if ($view['vstyle']=="mobile")
1026: 	{
1027: 	$ob[]="</html>";
1028: 	}
1029: else if ($view['vstyle']=="plain")
1030: 	{
1031: 	$ob[]="</html>";
1032: 	}
1033: else // standard and catch-all
1034: 	{
1035: 	$ob[]="<table class=\"nfooter\" width=100%>";
1036: 	$ob[]="<tr><td align=left>Powered by <a href=http://www.purplepixie.org/freenats/>FreeNATS</a>";
1037: 	$ob[]="</td><td align=right>";
1038: 	$ob[]="<a href=".$abs.">Login to System</a>";
1039: 	$ob[]="</td></tr>";
1040: 	$ob[]="</table>";
1041: 	}
1042: 	
1043: 	
1044: 	
1045: // finally the output
1046: switch ($mode)
1047: 	{
1048: 	case "debug":	
1049: 	echo "<pre>";
1050: 	var_dump($items);
1051: 	echo "<br><br>";
1052: 	foreach($ob as $l)
1053: 		echo htmlspecialchars($l)."\n";
1054: 	break;
1055: 	
1056: 	case "js":
1057: 	//echo "<script type=\"text/javascript\">\n";
1058: 	
1059: 	/* DO NOT USE THE DOM ELEMENT POINTER -
1060: 	Will not work with any CSS or other elements - needs reworked using proper DOM elements
1061: 	*/
1062: 	
1063: 	if (isset($_REQUEST['element'])&&($_REQUEST['element']!="")) // write into a DOM element rather than just to the screen
1064: 		{
1065: 		$first=true;
1066: 		foreach($ob as $l)
1067: 			{
1068: 			if ($first)
1069: 				{
1070: 				$first=false;
1071: 				echo "var fnwrite = document.getElementById('".$_REQUEST['element']."');\n";
1072: 				echo "fnwrite.innerHTML='';\n";
1073: 				}
1074: 			$line = addslashes(trim($l));
1075: 			//if (strlen($line)>0)&&($line[strlen($line)-1]=="\n")) $line=substr($line,0,strlen($line)-2);
1076: 			echo "fnwrite.innerHTML = fnwrite.innerHTML + \"".$line."\";\n";
1077: 			}
1078: 		}
1079: 	else
1080: 		{
1081: 		foreach($ob as $l)
1082: 			{
1083: 			//if ($l[strlen($l)-1]=='\n') $l=substr($l,0,strlen($l)-1);
1084: 			$l=trim($l);
1085: 			echo "document.write(\"".addslashes($l)."\");\n";
1086: 			}
1087: 		}
1088: 	//echo "</script>\n";
1089: 	echo "\n";
1090: 	break;
1091: 	
1092: 	default:
1093: 	foreach($ob as $l)
1094: 		{
1095: 		echo $l;
1096: 		echo "\n";
1097: 		}
1098: 	}
1099: 
1100: ?>