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

  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: 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: }
119: return $ret;
120: }
121: 
122: function ViewGroup($groupid,$detail=true)
123: {
124: global $NATS;
125: $ret=array();
126: // Get Group Info
127: $ret['status']=$NATS->GroupAlertLevel($groupid);
128: $gq="SELECT * FROM fngroup WHERE groupid=".ss($groupid)." LIMIT 0,1";
129: $gr=$NATS->DB->Query($gq);
130: $grow=$NATS->DB->Fetch_Array($gr);
131: $NATS->DB->Free($gr);
132: $ret['name']=$grow['groupname'];
133: $ret['desc']=$grow['groupdesc'];
134: $ret['icon']=$grow['groupicon'];
135: $ret['link']="group.php?groupid=".$groupid;
136: 
137: // Node Detail
138: if ($detail)
139: 	{
140: 	$ret['detail']=array();
141: 	$a=0;
142: 	$lq="SELECT nodeid FROM fngrouplink WHERE groupid=".ss($groupid);
143: 	$lr=$NATS->DB->Query($lq);
144: 	while ($link=$NATS->DB->Fetch_Array($lr))
145: 		{
146: 		$nq="SELECT nodename,alertlevel FROM fnnode WHERE nodeid=\"".$link['nodeid']."\" AND nodeenabled=1 ORDER BY alertlevel DESC, weight ASC";
147: 		//$nq="SELECT nodename,alertlevel FROM fnnode";
148: 		$nq.=" LIMIT 0,1";
149: 		$nr=$NATS->DB->Query($nq);
150: 		$node=$NATS->DB->Fetch_Array($nr);
151: 		$ret['detail'][$a]['nodeid']=$link['nodeid'];
152: 		$ret['detail'][$a]['nodename']=$node['nodename'];
153: 		$ret['detail'][$a]['status']=$node['alertlevel'];
154: 		$ret['detail'][$a]['link']="node.php?nodeid=".$link['nodeid'];
155: 		$a++;
156: 		$NATS->DB->Free($nr);
157: 		}
158: 	$NATS->DB->Free($lr);
159: 	}
160: 	
161: return $ret;
162: }
163: 	
164: $q="SELECT * FROM fnviewitem WHERE viewid=".ss($_REQUEST['viewid'])." ORDER BY iweight ASC";
165: $r=$NATS->DB->Query($q);
166: while ($row=$NATS->DB->Fetch_Array($r))
167: 	{
168: 	$id=$row['viewitemid'];
169: 	$items[$id]=$row;
170: 	// get name (varying), status and detail dependent...
171: 	switch ($row['itype'])
172: 		{
173: 		case "node": 
174: 			$items[$id]['data']=ViewNode($row['ioption']);
175: 			break;
176: 			
177: 		case "allnodes": case "alertnodes":
178: 			$items[$id]['detail']=array();
179: 			if ($row['itype']=="allnodes") $q="SELECT nodeid FROM fnnode WHERE nodeenabled=1 ORDER BY `weight` ASC";
180: 			else if ($row['itype']=="alertnodes") $q="SELECT nodeid FROM fnnode WHERE nodeenabled=1 AND alertlevel>0 ORDER BY `weight` ASC";
181: 			$ret=$NATS->DB->Query($q);
182: 			//echo "!".$q."<br>";
183: 			$a=0;
184: 			while ($noderow=$NATS->DB->Fetch_Array($ret))
185: 				{
186: 				if ($row['idetail']==1) $det=true;
187: 				else $det=false;
188: 				$items[$id]['detail'][$a]['data']=ViewNode($noderow['nodeid'],$det);
189: 				$items[$id]['detail'][$a]['icolour']=$row['icolour'];
190: 				$items[$id]['detail'][$a]['idetail']=$row['idetail'];
191: 				$items[$id]['detail'][$a]['igraphic']=$row['igraphic'];
192: 				$items[$id]['detail'][$a++]['itextstatus']=$row['itextstatus'];
193: 				}
194: 			$NATS->DB->Free($ret);
195: 			break;
196: 			
197: 		case "allgroups": case "alertgroups":
198: 			$items[$id]['detail']=array();
199: 			$q="SELECT groupid FROM fngroup ORDER BY weight ASC";
200: 			$ret=$NATS->DB->Query($q);
201: 			$a=0;
202: 			while ($grouprow=$NATS->DB->Fetch_Array($ret))
203: 				{
204: 				if ( ($row['itype']=="allgroups") || ($NATS->GroupAlertLevel($grouprow['groupid'])>0) )
205: 					{
206: 					$items[$id]['detail'][$a]['data']=ViewGroup($grouprow['groupid'],$row['idetail']);
207: 					$items[$id]['detail'][$a]['icolour']=$row['icolour'];
208: 					$items[$id]['detail'][$a]['ioption']=$grouprow['groupid'];
209: 					$items[$id]['detail'][$a]['idetail']=$row['idetail'];
210: 					$items[$id]['detail'][$a]['igraphic']=$row['igraphic'];
211: 					$items[$id]['detail'][$a++]['itextstatus']=$row['itextstatus'];
212: 					}	
213: 				}
214: 			$NATS->DB->Free($ret);
215: 			break;
216: 			
217: 			case "group":
218: 				$items[$id]['data']=ViewGroup($row['ioption'],$row['idetail']);
219: 				break;
220: 			
221: 			case "testgraph":
222: 				// can't be arsed to do link here
223: 				break;
224: 				
225: 			case "alerts":
226: 				$c=0;
227: 				$alev=0;
228: 				$items[$id]['detail']=array();
229: 				$alq="SELECT nodeid,openedx,alertlevel FROM fnalert WHERE closedx=0";
230: 				$alr=$NATS->DB->Query($alq);
231: 				while ($al=$NATS->DB->Fetch_Array($alr))
232: 					{
233: 					$items[$id]['detail'][$c]['nodeid']=$al['nodeid'];
234: 					$items[$id]['detail'][$c]['link']="node.php?nodeid=".$al['nodeid'];
235: 					if ($al['alertlevel']>$alev) $alev=$al['alertlevel'];
236: 					$items[$id]['detail'][$c]['status']=$al['alertlevel'];
237: 					$c++;
238: 					}
239: 				$items[$id]['data']['status']=$alev;
240: 				$items[$id]['data']['alerts']=$c;
241: 				$NATS->DB->Free($alr);
242: 				break;
243: 				
244: 			case "testdetail":
245: 				// localtest only thus far
246: 				$tid=substr($row['ioption'],1,128);
247: 				$tquery="SELECT * FROM fnlocaltest WHERE localtestid=\"".ss($tid)."\" LIMIT 0,1";
248: 				$tres=$NATS->DB->Query($tquery);
249: 				if ($trow=$NATS->DB->Fetch_Array($tres))
250: 					{
251: 					$items[$id]['status']=$trow['alertlevel'];
252: 					$items[$id]['lastrunx']=$trow['lastrunx'];
253: 					$items[$id]['dtago']=dtago($trow['lastrunx']);
254: 					$items[$id]['vtime']=vdt($trow['lastrunx']);
255: 					$items[$id]['nodeid']=$trow['nodeid'];
256: 					}
257: 				$NATS->DB->Free($tres);
258: 				break;
259: 				
260: 		}
261: 		
262: 	}
263: 
264: // begin the buffering of output...
265: 
266: // title and header
267: if ($view['vstyle']=="plain")
268: 	{
269: 	$ob[]="<html><head>";
270: 	$ob[]="<style type=\"text/css\">";
271: 	$fp=@fopen("css/mini.css","r");
272: 	if ($fp)
273: 		{
274: 		while(!@feof($fp))
275: 			$ob[]=@fgets($fp,1024);
276: 		}
277: 	@fclose($fp);
278: 	$ob[]="</style>";
279: 	$ob[]="</head><body>";
280: 	}
281: else if ($view['vstyle']=="mobile")
282: 	{
283: 	$ob[]="<html><head>";
284: 	if ($view['vrefresh']>0) $ob[]="<meta http-equiv=\"refresh\" content=\"".$view['vrefresh']."\">";
285: 	$ob[]="<style type=\"text/css\">";
286: 	$fp=@fopen("css/mobile.css","r");
287: 	if ($fp)
288: 		{
289: 		while(!@feof($fp))
290: 			$ob[]=@fgets($fp,1024);
291: 		}
292: 	@fclose($fp);
293: 	$ob[]="</style>";
294: 	$ob[]="</head><body>";
295: 	}
296: else // standard and catch-all
297: 	{
298: 	$ob[]="<html><head>";
299: 	if ($view['vrefresh']>0) $ob[]="<meta http-equiv=\"refresh\" content=\"".$view['vrefresh']."\">";
300: 	$ob[]="<title>FreeNATS: ".$view['vtitle']."</title>";
301: 	$ob[]="<style type=\"text/css\">";
302: 	$fp=@fopen("css/main.css","r");
303: 	if ($fp>0)
304: 		{
305: 		while(!@feof($fp))
306: 			$ob[]=@fgets($fp,1024);
307: 		}
308: 	@fclose($fp);
309: 	$ob[]="</style>";
310: 	$ob[]="</head><body>";
311: 	$ob[]="<table width=100% class=\"maintitle\">";
312: 	$ob[]="<tr><td align=left valign=center>";
313: 	$ob[]="<b class=\"maintitle\">FreeNATS: ".$view['vtitle']."</b></td>";
314: 	$ob[]="</tr></table>";
315: 	$ob[]="<br>";
316: 	}
317: 
318: // now the items
319: 
320: function small_node($item)
321: {
322: global $abs,$view,$colon,$dashes;
323: $ob=array(); // our local copy
324: $uri=$abs.$item['data']['link'];
325: if ($view['vlinkv']!=0)
326: 	{
327: 	$uri=$abs."view.php?viewid=".$view['vlinkv'];
328: 	}
329: $link=$view['vclick'];
330: if ($link=="disabled") $l="<a href=#>";
331: else if ($link=="standard") $l="<a href=\"".$uri."\">";
332: else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
333: else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
334: else $l="<a href=#>";
335: 			
336: // alert lights only as no fancy full-on tables etc yet
337: if ($item['igraphic']>0) // actually therefore should only be ==1 with 2 being the "proper" one
338: 	{
339: 	$is="<img src=\"".$abs."images/lights/a".$item['data']['status'].".png\">&nbsp;";
340: 	$ob[]=$is;
341: 	}
342: 			
343: $ob[]=$l;
344: 			
345: if ($item['icolour']==1) $ob[]="<b class=\"al".$item['data']['status']."\">";
346: 			
347: $out=$item['data']['name'];
348: if ($item['itextstatus']==1) $out.=$colon." ".oText($item['data']['status']);
349: $ob[]=$out."</a>";
350: 	
351: if ($item['icolour']==1) $ob[]="</b>";
352: 
353: // detail like tests etc...
354: if ($item['idetail']>0)
355: 	{
356: 	$a=0;
357: 	foreach($item['data']['detail'] as $dline)
358: 		{
359: 		$a++;
360: 		$ob[]="<br>&nbsp;-&nbsp;";
361: 		if ($item['icolour']==1) $ob[]="<b class=\"al".$dline['status']."\">";
362: 		$out=$dline['item'];
363: 		if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']);
364: 		$ob[]=$out;
365: 		if ($item['icolour']==1) $ob[]="</b>";
366: 		}
367: 	//if ($a>0) $ob[]="<br>";
368: 	}
369: 
370: return $ob;
371: }
372: 
373: function large_node($item)
374: {
375: global $abs,$view,$colon,$dashes;
376: $ob=array(); // our local copy
377: $uri=$abs.$item['data']['link'];
378: if ($view['vlinkv']!=0)
379: 	{
380: 	$uri=$abs."view.php?viewid=".$view['vlinkv'];
381: 	}
382: $link=$view['vclick'];
383: if ($link=="disabled") $l="<a href=#>";
384: else if ($link=="standard") $l="<a href=\"".$uri."\">";
385: else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
386: else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
387: else $l="<a href=#>";
388: 
389: if ($item['icolour']==1) $col=true;
390: else $col=false;
391: 
392: if ($col)
393: 	{
394: 	switch($item['data']['status'])
395: 		{
396: 		case -1: $c="#a0a0a0"; break;
397: 		case 0: $c="green"; break;
398: 		case 1: $c="orange"; break;
399: 		case 2: $c="red"; break;
400: 		default: $c="black"; break;
401: 		}
402: 	}
403: else $c="#a0a0a0";			
404: $ss="width: 250; border: dotted 1px ".$c.";";
405: 
406: $ob[]="<table style=\"".$ss."\">";
407: 
408: if ($item['igraphic']==1)
409: 	{
410: 	$is="<img src=\"".$abs."images/lights/a".$item['data']['status'].".png\">&nbsp;";
411: 	}			
412: else if ($item['igraphic']>0)
413: 	{
414: 	$is="<img src=\"".$abs."icons/".NodeIcon($item['data']['nodeid'])."\">&nbsp;";
415: 	}
416: else $is="&nbsp;";
417: 
418: $ob[]="<tr><td align=left valign=center>";
419: $ob[]=$l;
420: if ($item['icolour']==1) $ob[]="<b class=\"al".$item['data']['status']."\">";
421: 			
422: $out=$item['data']['name'];
423: if ($item['itextstatus']==1) $out.=$colon." ".oText($item['data']['status']);
424: $ob[]=$out."</a>";
425: 	
426: if ($item['icolour']==1) $ob[]="</b>";
427: $ob[]="</td><td align=right valign=center>";
428: $ob[]=$is;
429: $ob[]="</td></tr>";
430: // detail like tests etc...
431: if ($item['idetail']>0)
432: 	{
433: 	$ob[]="<tr><td colspan=2 align=left valign=top>";
434: 	$a=0;
435: 	foreach($item['data']['detail'] as $dline)
436: 		{
437: 		$a++;
438: 		$ob[]="&nbsp;-&nbsp;";
439: 		if ($item['icolour']==1) $ob[]="<b class=\"al".$dline['status']."\">";
440: 		$out=$dline['item'];
441: 		if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']);
442: 		$ob[]=$out;
443: 		if ($item['icolour']==1) $ob[]="</b>";
444: 		$ob[]="<br>";
445: 		}
446: 	$ob[]="</td></tr>";
447: 	//if ($a>0) $ob[]="<br>";
448: 	}
449: 
450: 	
451: $ob[]="</table>";
452: return $ob;
453: }
454: 
455: function large_group($item)
456: 	{
457: 	global $abs,$view,$colon,$dashes;
458: 	$ob=array(); // our local copy
459: 	$uri=$abs.$item['data']['link'];
460: 	if ($view['vlinkv']!=0)
461: 		{
462: 		$uri=$abs."view.php?viewid=".$view['vlinkv'];
463: 		}
464: 	$link=$view['vclick'];
465: 	if ($link=="disabled") $l="<a href=#>";
466: 	else if ($link=="standard") $l="<a href=\"".$uri."\">";
467: 	else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
468: 	else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
469: 	else $l="<a href=#>";
470: 	
471: 	if ($item['icolour']==1) $col=true;
472: 	else $col=false;
473: 	
474: 	if ($col)
475: 		{
476: 		switch($item['data']['status'])
477: 			{
478: 			case -1: $c="#a0a0a0"; break;
479: 			case 0: $c="green"; break;
480: 			case 1: $c="orange"; break;
481: 			case 2: $c="red"; break;
482: 			default: $c="black"; break;
483: 			}
484: 		}
485: 	else $c="#a0a0a0";			
486: 	$ss="width: 250; border: dotted 1px ".$c.";";
487: 	
488: 	$ob[]="<table style=\"".$ss."\">";
489: 	
490: 	if ($item['igraphic']==1)
491: 		{
492: 		$is="<img src=\"".$abs."images/lights/a".$item['data']['status'].".png\">&nbsp;";
493: 		}			
494: 	else if ($item['igraphic']>0)
495: 		{
496: 		$is="<img src=\"".$abs."icons/".GroupIcon($item['ioption'])."\">&nbsp;";
497: 		}
498: 	else $is="&nbsp;";
499: 	
500: 	$ob[]="<tr><td align=left valign=center>";
501: 	$ob[]=$l;
502: 	if ($item['icolour']==1) $ob[]="<b class=\"al".$item['data']['status']."\">";
503: 				
504: 	$out=$item['data']['name'];
505: 	if ($item['itextstatus']==1) $out.=$colon." ".oText($item['data']['status']);
506: 	$ob[]=$out."</a>";
507: 		
508: 	if ($item['icolour']==1) $ob[]="</b>";
509: 	$ob[]="</td><td align=right valign=center>";
510: 	$ob[]=$is;
511: 	$ob[]="</td></tr>";
512: 	
513: 	if ($item['data']['desc']!="") $ob[]="<tr><td colspan=2><i>".$item['data']['desc']."</i></td></tr>";
514: 	
515: 	// detail like tests etc...
516: 	if ($item['idetail']>0)
517: 		{
518: 		$ob[]="<tr><td colspan=2 align=left valign=top>";
519: 		$a=0;
520: 		foreach($item['data']['detail'] as $dline)
521: 			{
522: 			$a++;
523: 			$ob[]="&nbsp;-&nbsp;";
524: 			
525: 			$uri=$abs.$item['data']['link'];
526: 			if ($view['vlinkv']!=0)
527: 				{
528: 				$uri=$abs."view.php?viewid=".$view['vlinkv'];
529: 				}
530: 			$link=$view['vclick'];
531: 			if ($link=="disabled") $l="<a href=#>";
532: 			else if ($link=="standard") $l="<a href=\"".$uri."\">";
533: 			else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
534: 			else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
535: 			else $l="<a href=#>";
536: 			$ob[]=$l;
537: 			if ($item['icolour']==1) $ob[]="<b class=\"al".$dline['status']."\">";
538: 			if ($dline['nodename']!="") $out=$dline['nodename'];
539: 			else $out=$dline['nodeid'];
540: 			if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']);
541: 			$ob[]=$out."</a>";
542: 			if ($item['icolour']==1) $ob[]="</b>";
543: 			$ob[]="<br>";
544: 			}
545: 		$ob[]="</td></tr>";
546: 		//if ($a>0) $ob[]="<br>";
547: 		}
548: 	
549: 		
550: 	$ob[]="</table>";
551: 	return $ob;
552: }
553: 
554: function small_group($item)
555: 	{
556: 	global $abs,$view,$colon,$dashes;
557: 	$ob=array(); // our local copy
558: 	$uri=$abs.$item['data']['link'];
559: 	if ($view['vlinkv']!=0)
560: 		{
561: 		$uri=$abs."view.php?viewid=".$view['vlinkv'];
562: 		}
563: 	$link=$view['vclick'];
564: 	if ($link=="disabled") $l="<a href=#>";
565: 	else if ($link=="standard") $l="<a href=\"".$uri."\">";
566: 	else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
567: 	else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
568: 	else $l="<a href=#>";
569: 				
570: 	// alert lights only as no fancy full-on tables etc yet
571: 	if ($item['igraphic']>0) // actually therefore should only be ==1 with 2 being the "proper" one
572: 		{
573: 		$is="<img src=\"".$abs."images/lights/a".$item['data']['status'].".png\">&nbsp;";
574: 		$ob[]=$is;
575: 		}
576: 				
577: 	$ob[]=$l;
578: 				
579: 	if ($item['icolour']==1) $ob[]="<b class=\"al".$item['data']['status']."\">";
580: 				
581: 	$out=$item['data']['name'];
582: 	if ($item['itextstatus']==1) $out.=$colon." ".oText($item['data']['status']);
583: 	$ob[]=$out."</a>";
584: 		
585: 	if ($item['icolour']==1) $ob[]="</b>";
586: 	
587: 	// detail like tests etc...
588: 	if ($item['idetail']>0)
589: 		{
590: 		$a=0;
591: 		foreach($item['data']['detail'] as $dline)
592: 			{
593: 			$a++;
594: 			$uri=$abs.$item['data']['link'];
595: 			if ($view['vlinkv']!=0)
596: 				{
597: 				$uri=$abs."view.php?viewid=".$view['vlinkv'];
598: 				}
599: 			$link=$view['vclick'];
600: 			if ($link=="disabled") $l="<a href=#>";
601: 			else if ($link=="standard") $l="<a href=\"".$uri."\">";
602: 			else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
603: 			else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
604: 			else $l="<a href=#>";
605: 			$ob[]="<br>&nbsp;-&nbsp;";
606: 			$ob[]=$l;
607: 			if ($item['icolour']==1) $ob[]="<b class=\"al".$dline['status']."\">";
608: 			if ($dline['nodename']=="") $out=$dline['nodeid'];
609: 			else $out=$dline['nodename'];
610: 			if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']);
611: 			$ob[]=$out."</a>";
612: 			if ($item['icolour']==1) $ob[]="</b>";
613: 			}
614: 		//if ($a>0) $ob[]="<br>";
615: 		}
616: 	
617: 	return $ob;
618: 	}
619: 
620: function small_alerts($item)
621: 	{
622: 	global $abs,$view,$colon,$dashes;
623: 	$ob=array(); // our local copy
624: 	$uri=$abs."monitor.php";
625: 	if ($view['vlinkv']!=0)
626: 		{
627: 		$uri=$abs."view.php?viewid=".$view['vlinkv'];
628: 		}
629: 	$link=$view['vclick'];
630: 	if ($link=="disabled") $l="<a href=#>";
631: 	else if ($link=="standard") $l="<a href=\"".$uri."\">";
632: 	else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
633: 	else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
634: 	else $l="<a href=#>";
635: 				
636: 	// alert lights only as no fancy full-on tables etc yet
637: 	if ($item['igraphic']>0) // actually therefore should only be ==1 with 2 being the "proper" one
638: 		{
639: 		$is="<img src=\"".$abs."images/lights/a".$item['data']['status'].".png\">&nbsp;";
640: 		//$ob[]=$is;
641: 		}
642: 				
643: 	$ob[]=$l;
644: 				
645: 	if ($item['icolour']==1) $ob[]="<b class=\"al".$item['data']['status']."\">";
646: 				
647: 	if ($item['data']['alerts']==0) $out="No System Alerts";
648: 	else $out="System Alerts (".$item['data']['alerts'].")";
649: 	$ob[]=$out."</a>";
650: 		
651: 	if ($item['icolour']==1) $ob[]="</b>";
652: 	
653: 	// detail like tests etc...
654: 	if ($item['idetail']>0)
655: 		{
656: 		$a=0;
657: 		if ($item['data']['alerts']==0)
658: 			{
659: 			$ob[]="<br>&nbsp;-&nbsp;<i>There are no alerts</i>";
660: 			}
661: 		else
662: 			{
663: 			foreach($item['detail'] as $dline)
664: 				{
665: 				$a++;
666: 				$ob[]="<br>&nbsp;-&nbsp;";
667: 				$uri=$abs.$dline['link'];
668: 				if ($view['vlinkv']!=0)
669: 					{
670: 					$uri=$abs."view.php?viewid=".$view['vlinkv'];
671: 					}
672: 				$link=$view['vclick'];
673: 				if ($link=="disabled") $l="<a href=#>";
674: 				else if ($link=="standard") $l="<a href=\"".$uri."\">";
675: 				else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
676: 				else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
677: 				else $l="<a href=#>";
678: 				$ob[]=$l;	
679: 
680: 				if ($item['icolour']==1) $ob[]="<b class=\"al".$dline['status']."\">";
681: 				$out=$dline['nodeid'];
682: 				if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']);
683: 				$ob[]=$out."</a>";
684: 				if ($item['icolour']==1) $ob[]="</b>";
685: 				}
686: 			//if ($a>0) $ob[]="<br>";
687: 			}
688: 		}
689: 	$ob[]="<br>";
690: 	
691: 	return $ob;
692: }
693: 
694: 
695: function large_alerts($item)
696: 	{
697: 	global $abs,$view,$colon,$dashes;
698: 	$ob=array(); // our local copy
699: 	$uri=$abs."monitor.php";
700: 	if ($view['vlinkv']!=0)
701: 		{
702: 		$uri=$abs."view.php?viewid=".$view['vlinkv'];
703: 		}
704: 	$link=$view['vclick'];
705: 	if ($link=="disabled") $l="<a href=#>";
706: 	else if ($link=="standard") $l="<a href=\"".$uri."\">";
707: 	else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
708: 	else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
709: 	else $l="<a href=#>";
710: 
711: 	if ($item['icolour']==1) $col=true;
712: 	else $col=false;
713: 	
714: 	if ($col)
715: 		{
716: 		switch($item['data']['status'])
717: 			{
718: 			case -1: $c="#a0a0a0"; break;
719: 			case 0: $c="green"; break;
720: 			case 1: $c="orange"; break;
721: 			case 2: $c="red"; break;
722: 			default: $c="black"; break;
723: 			}
724: 		}
725: 	else $c="#a0a0a0";			
726: 	$ss="width: 250; border: dotted 1px ".$c.";";
727: 	
728: 	$ob[]="<table style=\"".$ss."\">";
729: 	
730: 
731: 
732: 	// alert lights only as no fancy full-on tables etc yet
733: 	if ($item['igraphic']>0) // actually therefore should only be ==1 with 2 being the "proper" one
734: 		{
735: 		$is="<img src=\"".$abs."images/lights/a".$item['data']['status'].".png\">&nbsp;";
736: 		//$ob[]=$is;
737: 		}
738: 	else $is="&nbsp;";		
739: 	
740: 	$ob[]="<tr><td align=left valign=center>";
741: 				
742: 	if ($item['icolour']==1) $ob[]="<b class=\"al".$item['data']['status']."\">";
743: 				
744: 	if ($item['data']['alerts']==0) $out="No System Alerts";
745: 	else $out="System Alerts (".$item['data']['alerts'].")";
746: 	$ob[]=$out."</a>";
747: 		
748: 	if ($item['icolour']==1) $ob[]="</b>";
749: 	
750: 	$ob[]="</td><td align=right valign=center>";
751: 	$ob[]=$is;
752: 	$ob[]="</td></tr>";
753: 	
754: 	// detail like tests etc...
755: 	if ($item['idetail']>0)
756: 		{
757: 		$a=0;
758: 		if ($item['data']['alerts']==0)
759: 			{
760: 			$ob[]="<tr><td colspan=2 align=left>&nbsp;-&nbsp;<i>There are no alerts</i></td></tr>";
761: 			}
762: 		else
763: 			{
764: 			foreach($item['detail'] as $dline)
765: 				{
766: 				$a++;
767: 				$ob[]="<tr><td colspan=2>&nbsp;-&nbsp;";
768: 				$uri=$abs.$dline['link'];
769: 				if ($view['vlinkv']!=0)
770: 					{
771: 					$uri=$abs."view.php?viewid=".$view['vlinkv'];
772: 					}
773: 				$link=$view['vclick'];
774: 				if ($link=="disabled") $l="<a href=#>";
775: 				else if ($link=="standard") $l="<a href=\"".$uri."\">";
776: 				else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
777: 				else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
778: 				else $l="<a href=#>";
779: 				$ob[]=$l;	
780: 
781: 				if ($item['icolour']==1) $ob[]="<b class=\"al".$dline['status']."\">";
782: 				$out=$dline['nodeid'];
783: 				if ($item['itextstatus']==1) $out.=$colon." ".oText($dline['status']);
784: 				$ob[]=$out."</a>";
785: 				if ($item['icolour']==1) $ob[]="</b>";
786: 				$ob[]="</td></tr>";
787: 				}
788: 			//if ($a>0) $ob[]="<br>";
789: 			}
790: 		}
791: 	$ob[]="</table>";
792: 	
793: 	return $ob;
794: 
795: 
796: 
797: 	}
798: 
799: 
800: 
801: 
802: 
803: if ($view['vcolumns']>1)
804: 	{
805: 	$usecols=true;
806: 	$colcount=$view['vcolumns'];
807: 	}
808: else $usecols=false;
809: 
810: foreach($items as $item)
811: 	{
812: 	switch ($item['itype'])
813: 		{
814: 		case "node":
815: 			if ($item['isize']>0) $output=large_node($item);
816: 			else $output=small_node($item);
817: 			foreach($output as $line) $ob[]=$line;
818: 			
819: 			break;
820: 			
821: 		case "group":
822: 			if ($item['isize']>0) $output=large_group($item);
823: 			else $output=small_group($item);
824: 			foreach($output as $line) $ob[]=$line;
825: 			break;
826: 			
827: 		case "alerts":
828: 			if ($item['isize']>0) $output=large_alerts($item);
829: 			else $output=small_alerts($item);
830: 			foreach($output as $line) $ob[]=$line;
831: 			break;
832: 			
833: 		case "allnodes": case "alertnodes":
834: 			$c=0;
835: 			if ($usecols) $ob[]="<table border=0>";
836: 			foreach($item['detail'] as $node)
837: 				{
838: 				if ($usecols)
839: 					{
840: 					if ($c==0) $ob[]="<tr>";
841: 					$ob[]="<td align=left valign=top>";
842: 					}
843: 				if ($item['isize']==1) $output=large_node($node);
844: 				else $output=small_node($node);
845: 				foreach($output as $line) $ob[]=$line;
846: 				
847: 				if ($usecols)
848: 					{
849: 					$ob[]="</td>";
850: 					$c++;
851: 					if ($c>=$colcount)
852: 						{
853: 						$ob[]="</tr>";
854: 						$ob[]="<tr><td colspan=".$colcount.">&nbsp;</td></tr>";
855: 						$c=0;
856: 						}
857: 					}
858: 				else $ob[]="<br>";
859: 				}
860: 			if (($usecols) && ($c<3)) $ob[]="</tr>";
861: 			if ($usecols) $ob[]="</table>";
862: 			break;
863: 			
864: 		case "allgroups": case "alertgroups":
865: 			$c=0;
866: 			if ($usecols) $ob[]="<table border=0>";
867: 			foreach($item['detail'] as $group)
868: 				{
869: 				if ($usecols)
870: 					{
871: 					if ($c==0) $ob[]="<tr>";
872: 					$ob[]="<td align=left valign=top>";
873: 					}
874: 				if ($item['isize']==1) $output=large_group($group);
875: 				else $output=small_group($group);
876: 				foreach($output as $line) $ob[]=$line;
877: 				
878: 				if ($usecols)
879: 					{
880: 					$ob[]="</td>";
881: 					$c++;
882: 					if ($c>=$colcount)
883: 						{
884: 						$ob[]="</tr>";
885: 						$ob[]="<tr><td colspan=".$colcount.">&nbsp;</td></tr>";
886: 						$c=0;
887: 						}
888: 					}
889: 				else $ob[]="<br>";
890: 				}
891: 			if (($usecols) && ($c<3)) $ob[]="</tr>";
892: 			if ($usecols) $ob[]="</table>";
893: 			break;
894: 			
895: 		case "title":
896: 			if ($item['isize']>0) $ob[]="<b style=\"font-size: 14pt;\">";
897: 			else if ($item['icolour']==1) $ob[]="<b>";
898: 			$ob[]=$item['ioption'];
899: 			if ( ($item['isize']>0) || ($item['icolour']==1) ) $ob[]="</b>";
900: 			break;
901: 			
902: 		case "testdetail":
903: 		
904: 			$is="";
905: 			if ($item['igraphic']>0)
906: 				{
907: 				$is="<img src=\"".$abs."images/lights/a".$item['status'].".png\">&nbsp;";
908: 				}
909: 				
910: 			if ($is!="") $ob[]=$is;
911: 		
912: 			$uri=$abs."node.php?nodeid=".$item['nodeid'];
913: 			if ($view['vlinkv']!=0)
914: 				{
915: 				$uri=$abs."view.php?viewid=".$view['vlinkv'];
916: 				}
917: 			$link=$view['vclick'];
918: 			if ($link=="disabled") $l="<a href=#>";
919: 			else if ($link=="standard") $l="<a href=\"".$uri."\">";
920: 			else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
921: 			else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
922: 			else $l="<a href=#>";
923: 			$ob[]=$l;
924: 			
925: 			if ($item['icolour']==1) $ob[]="<b class=\"al".$item['status']."\">";
926: 			else $ob[]="<b>";
927: 			
928: 			$s=$item['iname'];
929: 			if ($item['itextstatus']==1) $s.=$colon." ".oText($item['status']);
930: 			$s.="</a>";
931: 			$ob[]=$s;
932: 			if ($item['idetail']>0)
933: 				{
934: 				if ($item['isize']>0) $ob[]="<br>&nbsp;".$dash."&nbsp;tested ";
935: 				else $ob[]=$dash." ";
936: 				$ob[]=$item['vtime'];
937: 				}
938: 			$ob[]="</b>";
939: 				
940: 			break;
941: 			
942: 		case "testgraph":
943: 			$p=strpos($item['ioption'],"/");
944: 			if ($p===false)
945: 				{
946: 				$hrs=24;
947: 				$tid=$item['ioption'];
948: 				}
949: 			else
950: 				{
951: 				$tid=substr($item['ioption'],0,$p);
952: 				$hrs=substr($item['ioption'],$p+1,20);
953: 				}
954: 			if ($item['isize']>0)
955: 				{
956: 				$width=700;
957: 				$height=150;
958: 				}
959: 			else
960: 				{
961: 				$width=350;
962: 				$height=100;
963: 				}
964: 			// colours eventually...
965: 			
966: 			$uri=$abs."history.test.php?testid=".$tid;
967: 			if ($view['vlinkv']!=0)
968: 				{
969: 				$uri=$abs."view.php?viewid=".$view['vlinkv'];
970: 				}
971: 			$link=$view['vclick'];
972: 			if ($link=="disabled") $l="<a href=#>";
973: 			else if ($link=="standard") $l="<a href=\"".$uri."\">";
974: 			else if ($link=="frametop") $l="<a href=\"".$uri."\" target=_top>";
975: 			else if ($link=="newwindow") $l="<a href=\"".$uri."\" target=top>";
976: 			else $l="<a href=#>";
977: 			
978: 			
979: 			$i=$abs."test.graph.php?testid=".$tid;
980: 			$graphkey=$NATS->Cfg->Get("site.graph.key","");
981: 			if ($graphkey!="") $i.="&graphkey=".$graphkey;
982: 			$i.="&startx=";
983: 			$now=time();
984: 			$startx=$now-($hrs*60*60);
985: 			$i.=$startx."&finishx=".$now."&width=".$width."&height=".$height;
986: 			$ob[]=$l."<img src=\"".$i."\" border=0></a>";
987: 			break;
988: 			
989: 		}
990: 		$ob[]="<br>";
991: 		
992: 	}
993: 	
994: // footer
995: if ($view['vstyle']=="mobile")
996: 	{
997: 	$ob[]="</html>";
998: 	}
999: else if ($view['vstyle']=="plain")
1000: 	{
1001: 	$ob[]="</html>";
1002: 	}
1003: else // standard and catch-all
1004: 	{
1005: 	$ob[]="<table class=\"nfooter\" width=100%>";
1006: 	$ob[]="<tr><td align=left>Powered by <a href=http://www.purplepixie.org/freenats/>FreeNATS</a>";
1007: 	$ob[]="</td><td align=right>";
1008: 	$ob[]="<a href=".$abs.">Login to System</a>";
1009: 	$ob[]="</td></tr>";
1010: 	$ob[]="</table>";
1011: 	}
1012: 	
1013: 	
1014: 	
1015: // finally the output
1016: switch ($mode)
1017: 	{
1018: 	case "debug":	
1019: 	echo "<pre>";
1020: 	var_dump($items);
1021: 	echo "<br><br>";
1022: 	foreach($ob as $l)
1023: 		echo htmlspecialchars($l)."\n";
1024: 	break;
1025: 	
1026: 	case "js":
1027: 	//echo "<script type=\"text/javascript\">\n";
1028: 	//echo "document.write(\"hello world\");\n";
1029: 	foreach($ob as $l)
1030: 		{
1031: 		//if ($l[strlen($l)-1]=='\n') $l=substr($l,0,strlen($l)-1);
1032: 		$l=trim($l);
1033: 		echo "document.write(\"".addslashes($l)."\");\n";
1034: 		}
1035: 	//echo "</script>\n";
1036: 	echo "\n";
1037: 	break;
1038: 	
1039: 	default:
1040: 	foreach($ob as $l)
1041: 		{
1042: 		echo $l;
1043: 		echo "\n";
1044: 		}
1045: 	}
1046: 
1047: ?>