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