File: 1.01.10a/server/base/screen.inc.php (View as HTML)

  1: <?php // screen.inc.php -- web page screen library
  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: $menu=array();
 24: $menu[0]="<a href=http://www.purplepixie.org/freenats/>FreeNATS Homepage</a>";
 25: $menu[1]="<a href=monitor.php>Live Monitor</a>&nbsp; &nbsp;<a href=main.php>Configuration</a>&nbsp; &nbsp;";
 26: $menu[1].="<a href=http://www.purplepixie.org/freenats/support.php target=top>Help</a>&nbsp; &nbsp;<a href=logout.php>Logout</a>";
 27: $menu[2]=$menu[1]."&nbsp; &nbsp;<a href=admin.php>Admin</a>";
 28: 
 29: $menu[3]="<a href=iphone.php>iPhone Interface</a>&nbsp;  &nbsp;<a href=http://www.purplepixie.org/freenats/>FreeNATS Homepage</a>";
 30: 
 31: $pagemenu['main']="<a href=main.php?mode=overview>Overview</a>&nbsp; &nbsp;<a href=main.php?mode=nodes>Nodes</a>&nbsp; &nbsp;";
 32: $pagemenu['main'].="<a href=main.php?mode=groups>Groups</a>&nbsp; &nbsp;<a href=main.php?mode=views>Views &amp; Reports</a>&nbsp; &nbsp;";
 33: $pagemenu['main'].="<a href=pref.php>User Options</a>";
 34: 
 35: $pagemenu=array();
 36: $pagemenu['main']=array(
 37: 	array("overview","main.php?mode=overview","Overview"),
 38: 	array("nodes","main.php?mode=nodes","Nodes"),
 39: 	array("groups","main.php?mode=groups","Groups"),
 40: 	array("views","main.php?mode=views","Views &amp; Reports"),
 41: 	array("pref","pref.php?mode=pref","User Options"),
 42: 	array("admin","admin.php","System Settings") );
 43: 	
 44: function PageMenu($name,$mode="")
 45: {
 46: global $pagemenu;
 47: if (($mode=="")&&isset($_REQUEST['mode'])) $mode=$_REQUEST['mode'];
 48: $out="";
 49: $first=true;
 50: foreach($pagemenu[$name] as $opt)
 51: 	{
 52: 	if ($first) $first=false;
 53: 	else $out.=" ";
 54: 	if ($mode!=$opt[0]) $out.="&nbsp;<a href=".$opt[1].">";
 55: 	else $out.="<b style=\"background-color: #ffffff;\">&nbsp;<a href=\"".$opt[1]."\" style=\"color: black; text-decoration: none;\">";
 56: 	$out.=$opt[2];
 57: 	if ($mode!=$opt[0]) $out.="</a>&nbsp; ";
 58: 	else $out.="</a>&nbsp;</b>";
 59: 	}
 60: return $out;
 61: }
 62: 	
 63: $poplist=array();
 64: 
 65: function Screen_Header($title,$menuindex=0,$alertpane=0,$ah="",$pagemenu="",$pagemenumode="")
 66: {
 67: global $menu,$NATS,$NATS_Session;
 68: if ($NATS->Cfg->Get("site.enable.interactive")!=1)
 69: 	{
 70: 	echo "Sorry but FreeNATS interactive is disabled.<br>";
 71: 	echo "<i>site.enable.interactive</i> != 1<br><br>";
 72: 	$NATS->Stop();
 73: 	exit();
 74: 	}
 75: if ($menuindex==1) $alertpane=1; // bodge
 76: //if ($NATS_Session->userlevel>9) $menuindex=2; // further bodge!
 77: echo "<html><head><title>FreeNATS: ".$title."</title>\n";
 78: echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"css/main.css\">\n";
 79: /*
 80: echo "<style type=\"text/css\">\n";
 81: require("css/main.css");
 82: echo "\n</style>\n";
 83: */
 84: if ($ah!="") echo $ah;
 85: echo "</head>\n";
 86: echo "<script type=\"text/javascript\" src=\"js/freenats.js\"></script>\n";
 87: echo "<body>";
 88: 
 89: echo "<table class=\"maintitle\" cellspacing=0 cellpadding=0>\n";
 90: echo "<tr><td align=left valign=center class=\"mainleft\">\n";
 91: echo "<b class=\"maintitle\">".$title."</b>";
 92: if ($pagemenu!="") echo "<br>&nbsp;&nbsp;<b>".PageMenu($pagemenu,$pagemenumode)."</b>";
 93: echo "</td>\n";
 94: echo "<td class=\"titlelink\" align=right valign=center>\n";
 95: echo $menu[$menuindex];
 96: echo "&nbsp;</td></tr>\n";
 97: //echo "<tr><td align=left valign=bottom><img src=images/e0e0ff.10px.bl.jpg></td>";
 98: //echo "</tr>\n";
 99: echo "</table>\n";
100: 
101: if ($alertpane==1)
102: 	{
103: 	$alerts=$NATS->GetAlerts();
104: 	if (is_array($alerts))
105: 		{
106: 		echo "<div class=\"alertpane\" id=\"fn_alertpane\">";
107: 		echo "<b><u>NATS Alerts</u></b><br><br>";
108: 		foreach($alerts as $alert)
109: 			{
110: 			echo "&nbsp;<a href=node.php?nodeid=".$alert['nodeid'].">";
111: 			echo "<b class=\"al".$alert['alertlevel']."\">".$alert['nodeid']."</b></a><br>";
112: 			}
113: 		echo "<br>";
114: 		echo "</div>";
115: 		}
116: 	}
117: 
118: }
119: 
120: function Start_Round($title,$width="")
121: {
122: if ($width!="") $w=" width=".$width;
123: else $w="";
124: echo "<table border=0".$w." cellspacing=0 cellpadding=0>\n";
125: echo "<tr><td valign=top align=left width=11 style=\"background-color: #e0e0ff;\"><img src=images/e0e0ff.10px.tl.jpg></td>\n";
126: echo "<td align=left valign=center style=\"background-color: #e0e0ff;\">\n";
127: echo $title;
128: echo "\n</td><td align=right valign=top style=\"background-color: #e0e0ff;\"><img src=images/e0e0ff.10px.tr.jpg></td></tr>\n";
129: echo "<tr><td colspan=3 style=\"border-left: solid 1px #e0e0ff; border-bottom: solid 1px #e0e0ff; border-right: solid 1px #e0e0ff; padding: 5px;\">\n";
130: }
131: 
132: function End_Round()
133: {
134: echo "\n</td></tr>\n";
135: 
136: echo "</table>";
137: }
138: 
139: function Screen_Footer($track_if_enabled=true)
140: {
141: global $NATS,$poplist;
142: echo "<br><br>\n";
143: //$NATS->Cfg->DumpToScreen();
144: echo "<div class=\"nfooter\">";
145: echo "<div class=\"bl\"><div class=\"br\"><div class=\"tl\"><div class=\"tr\">";
146: 
147: echo "<div align=\"left\" class=\"nfootleft\"><a href=http://www.purplepixie.org/freenats/>FreeNATS</a>; &copy; Copyright 2008 ";
148: echo "<a href=http://www.purplepixie.org/>PurplePixie Systems</a>";
149: echo "</div><div class=\"nfootright\">";
150: echo "Version: ".$NATS->Version;
151: if ($NATS->Release!="") echo "/".$NATS->Release;
152: echo "&nbsp;&nbsp;</div>";
153: 
154: //echo "Hello";
155: echo "</div></div></div></div>";
156: echo "</div>";
157: if (ini_get("freenats.rpath")==1)
158: 	{
159: 	echo "<i>FreeNATS Virtual Server Powered By <a href=http://www.rpath.org/>rPath</a> LAMP Appliance</i><br>";
160: 	}
161: //echo "<i>This is alpha-test software - we would very much value your ";
162: //echo "<a href=http://www.purplepixie.org/freenats/feedback.php>feedback</a></i><br>";
163: if ($track_if_enabled)
164: 	{
165: 	$t=$NATS->Cfg->Get("freenats.tracker");
166: 	if ( ($t!="") && ($t>0) )
167: 		{
168: 		$sn=explode("/",$_SERVER['SCRIPT_NAME']);
169: 		$script=$sn[count($sn)-1];
170: 		echo "<img src=\"http://www.purplepixie.org/freenats/report/ping.png.php?data=v=".$NATS->Version."+p=".$script."&type=ping\" width=1 height=1>\n";
171: 		}
172: 	}
173: 
174: if ($NATS->Cfg->Get("site.popupmessage")=="1")
175: 	{
176: 	if (count($poplist)>0)
177: 		{
178: 		echo "\n<script type=\"text/javascript\">\n";
179: 		
180: 		foreach($poplist as $pop)
181: 			{
182: 			echo "alert('".$pop."');\n";
183: 			}
184: 			
185: 		echo "</script>\n";
186: 		}
187: 	}
188: echo "\n</body></html>\n";
189: }
190: 
191: function UL_Error($task="")
192: {
193: Screen_Header("Insufficient Access");
194: echo "<br>Sorry but your user has insufficient access to perform task (".$task.").<br><br>";
195: echo "<a href=main.php>Please click here to continue.</a><br><br>";
196: Screen_Footer();
197: exit();
198: }
199: 
200: function nicedt($ts)
201: {
202: global $NATS;
203: $form="H:i:s d/m/Y";
204: if (isset($NATS)) $form=$NATS->Cfg->Get("site.dtformat","H:i:s d/m/Y");
205: if ($ts<=0) return "never";
206: return date($form,$ts);
207: }
208: 
209: function enicedt($ts)
210: {
211: echo nicedt($ts);
212: }
213: 
214: function nicediff($diff)
215: {
216: $hr=0;
217: $mn=0;
218: $se=0;
219: if ($diff>59)
220: 	{
221: 	$mn=round($diff/60,0);
222: 	$se=$diff%60;
223: 	if ($mn>59)
224: 		{
225: 		$hr=round($mn/60,0);
226: 		$mn=$mn%60;
227: 		}
228: 	}
229: else $se=$diff;
230: $s="";
231: if ($hr<10) $s="0";
232: $s.=$hr.":";
233: if ($mn<10) $s.="0";
234: $s.=$mn.":";
235: if ($se<10) $s.="0";
236: $s.=$se;
237: return $s;
238: }
239: 
240: function dtago($ts,$sayago=true)
241: {
242: if ($ts<=0) return "never";
243: $now=time();
244: $diff=$now-$ts;
245: $s=nicediff($diff);
246: if ($sayago) $s.=" ago";
247: return $s;
248: }
249: 
250: function nicenextx($nextx)
251: {
252: if ($nextx<=0) return "Now";
253: $diff=$nextx-time();
254: if ($diff<0)
255: 	{
256: 	$sign=" ago";
257: 	$diff=0-$diff;
258: 	}
259: else $sign="";
260: return nicediff($diff).$sign;
261: }
262: 
263: function edtago($ts)
264: {
265: echo dtago($ts);
266: }
267: 
268: function smartx($x) // smart handling of unixtime x variables
269: {
270: if ($x==0) return time();	// 0 = now
271: else if ($x<0)				// -z = now - z seconds
272: 	return (time()+$x);		// negative number so +
273: else						// positive number so is a unixtime
274: 	return $x;
275: }
276: 
277: $allowed="00123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@_-.,:&/~%=+(){}[]#?";
278: 
279: function nices($s)
280: {
281: global $allowed;
282: $o="";
283: for ($a=0; $a<strlen($s); $a++)
284: 	{
285: 	$c=$s[$a];
286: 	if (strpos($allowed,$c)===false)
287: 		{
288: 		// skip it
289: 		}
290: 	else $o.=$c;
291: 	}
292: return $o;
293: }
294: /* // Old Static List Function
295: function ShowIcons()
296: {
297: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup;
298: $c=0;
299: echo "<table border=0>";
300: $cc=0;
301: for ($a=0; $a<count($fnIcons); $a++)
302: 	{
303: 	if ($cc==0) echo "<tr>";
304: 	echo "<td valign=top align=center><img src=icons/".$fnIcons[$a]."><br>".$fnIcons[$a]."<br>";
305: 	if ($a==$fnIcon_DefNode) echo "<i>Node Default</i> ";
306: 	if ($a==$fnIcon_DefGroup) echo "<i>Group Default</i>";
307: 	echo "</td>";
308: 	$cc++;
309: 	if ($cc>=5)
310: 		{
311: 		echo "</tr>";
312: 		$cc=0;
313: 		}
314: 	}
315: if ($cc>0) echo "</tr>";
316: echo "</table>";
317: }
318: */
319: 
320: function GetIcons()
321: {
322: $iconFiles=glob("icons/{*.gif,*.GIF,*.jpg,*.JPG,*.jpeg,*.JPEG,*.png,*.PNG}", GLOB_BRACE);
323: for($a=0;$a<count($iconFiles);$a++)
324: 	$iconFiles[$a]=substr($iconFiles[$a],6);
325: return $iconFiles;
326: }
327: 
328: 
329: function ShowIcons()
330: {
331: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup;
332: $c=0;
333: echo "<table border=0>";
334: $cc=0;
335: $iconFiles=GetIcons();
336: for ($a=0; $a<count($iconFiles); $a++)
337: 	{
338: 	$icon=$iconFiles[$a];
339: 	if ($cc==0) echo "<tr>";
340: 	echo "<td valign=top align=center><img src=icons/".$icon."><br>".$icon."<br>";
341: 	if ($icon==$fnIcons[$fnIcon_DefNode]) echo "<i>Node Default</i> ";
342: 	if ($a==$fnIcons[$fnIcon_DefGroup]) echo "<i>Group Default</i>";
343: 	echo "</td>";
344: 	$cc++;
345: 	if ($cc>=5)
346: 		{
347: 		echo "</tr>";
348: 		$cc=0;
349: 		}
350: 	}
351: if ($cc>0) echo "</tr>";
352: echo "</table>";
353: }
354: 
355: 
356: 
357: function NodeIcon($nodeid)
358: {
359: global $NATS,$fnIcons,$fnIcon_DefNode;
360: $q="SELECT nodeicon FROM fnnode WHERE nodeid=\"".ss($nodeid)."\"";
361: $r=$NATS->DB->Query($q);
362: if ($row=$NATS->DB->Fetch_Array($r)) 
363: 	{
364: 	if ($row['nodeicon']!="") return $row['nodeicon'];
365: 	}
366: return $fnIcons[$fnIcon_DefNode];
367: }
368: 
369: function GroupIcon($groupid)
370: {
371: global $NATS,$fnIcons,$fnIcon_DefGroup;
372: $q="SELECT groupicon FROM fngroup WHERE groupid=\"".ss($groupid)."\"";
373: $r=$NATS->DB->Query($q);
374: if ($row=$NATS->DB->Fetch_Array($r)) 
375: 	{
376: 	if ($row['groupicon']!="") return $row['groupicon'];
377: 	}
378: return $fnIcons[$fnIcon_DefGroup];
379: }
380: 
381: function np_tiny($nodeid,$text=true,$nodename="")
382: {
383: global $NATS;
384: $al=$NATS->NodeAlertLevel($nodeid);
385: echo "<table class=\"nptiny-al".$al."\">";
386: echo "<tr><td valign=center align=center>";
387: echo "<a href=node.php?nodeid=".$nodeid.">";
388: echo "<img src=\"icons/".NodeIcon($nodeid)."\" border=0>";
389: echo "</a>";
390: if ($text)
391: 	{
392: 	if ($nodename=="") $nodename=$nodeid;
393: 	
394: 	//$words=explode(" ",$nodename);
395: 	
396: 	// messy but there you go...
397: 	
398: 	$max_on_line=7;
399: 	$max_lines=2;
400: 	$len=strlen($nodename);
401: 	$out="";
402: 	$linecount=0;
403: 	$charcount=0;
404: 	for ($a=0; $a<$len; $a++)
405: 		{
406: 			
407: 		$char=$nodename[$a];
408: 		
409: 		if ($char==" ")
410: 			{
411: 			$linecount++;
412: 			$charcount=0;
413: 			}
414: 		else $charcount++;
415: 		
416: 		if ($charcount>=$max_on_line) 
417: 			{
418: 			$a=$len+10;
419: 			$out.="..";
420: 			}
421: 		else if ($linecount>=$max_lines) 
422: 			{
423: 			$a=$len+10;
424: 			$out.="..";
425: 			}
426: 		else $out.=$char;
427: 		
428: 		}
429: 	//if ($a==($len+10)) $out.="..";
430: 	$nodename=$out;
431: 	
432: 	$size=10;
433: 		
434: /* -- size-based	
435: 	$len=strlen($nodename);
436: 	if ($len<9) $size=10;
437: 	else if ($len<15) $size=8;
438: 	else if ($len<20) $size=7;
439: 	else
440: 		{
441: 		$size=6;
442: 		$nodename=substr($nodename,0,18)."..";
443: 		}
444: */
445: 	
446: 	echo "<br><b class=\"al".$al."\" style=\"font-size: ".$size."pt;\">".$nodename."</b>";
447: 	}
448: echo "</td></tr></table>";
449: }
450: 
451: function ng_tiny($groupid,$groupname="",$text=true)
452: {
453: global $NATS;
454: // to do - get groupname if not sent but F--- it for now
455: $al=$NATS->GroupAlertLevel($groupid);
456: echo "<table class=\"nptiny-al".$al."\">";
457: echo "<tr><td valign=center align=center>";
458: echo "<a href=group.php?groupid=".$groupid.">";
459: echo "<img src=\"icons/".GroupIcon($groupid)."\" border=0>";
460: echo "</a>";
461: if ($text)
462: 	{
463: 	echo "<br><b class=\"al".$al."\">".$groupname."</b>";
464: 	}
465: echo "</td></tr></table>";
466: }
467: 
468: function ng_big($groupid,$groupname="",$groupdesc="",$groupicon="")
469: {
470: global $NATS;
471: if ($groupicon=="") $groupicon=GroupIcon($groupid);
472: $al=$NATS->GroupAlertLevel($groupid);
473: echo "<table class=\"npbig-al".$al."\">";
474: echo "<tr><td align=left valign=top>";
475: echo "<table class=\"nicetable\" width=300>";
476: echo "<tr><td align=right>Group Name :";
477: echo "</td><td align=left><a href=group.php?groupid=".$groupid.">".$groupname."</a></td></tr>";
478: echo "<tr><td align=right>Description :";
479: echo "</td><td align=left>".$groupdesc."</td></tr>";
480: echo "<tr><td align=right>Status :</td><td align=left>";
481: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>";
482: echo "</table></td>";
483: //echo "<td align=left valign=top align=right width=60>";
484: //echo "<img src=icons/".GroupIcon($groupid).">";
485: //echo "</td>";
486: echo "</tr>";
487: echo "</table>";
488: }
489: 
490: function np_big($nodeid,$nodename="",$nodedesc="",$nodeicon="")
491: {
492: global $NATS;
493: if ($nodedesc=="") $nodedesc="&nbsp;";
494: if ($nodeicon=="") $nodeicon=NodeIcon($nodeid);
495: $al=$NATS->NodeAlertLevel($nodeid);
496: echo "<table class=\"npbig-al".$al."\">";
497: echo "<tr><td align=left valign=top>";
498: echo "<table class=\"nicetable\" width=300>";
499: echo "<tr><td align=right>Node Name :";
500: if ($nodename=="") $nodename=$nodeid;
501: echo "</td><td align=left><a href=node.php?nodeid=".$nodeid.">".$nodename."</a></td></tr>";
502: echo "<tr><td align=right>Description :";
503: echo "</td><td align=left>".$nodedesc."</td></tr>";
504: echo "<tr><td align=right>Status :</td><td align=left>";
505: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>";
506: echo "</table></td>";
507: //echo "<td align=left valign=top align=right width=60>";
508: //echo "<img src=icons/".GroupIcon($groupid).">";
509: //echo "</td>";
510: echo "</tr>";
511: echo "</table>";
512: }
513: 
514: function GetAbsolute($filename="")
515: { // sooooooooo messy but looks like the ONLY FRICKIN' WAY!
516: if ((isset($_SERVER['HTTPS']))&&($_SERVER['HTTPS']!="")) $uri="https://";
517: else $uri="http://";
518: $uri.=$_SERVER['HTTP_HOST'];
519: $uri.=$_SERVER['REQUEST_URI'];
520: $pos=strripos($uri,"/");
521: $rdir=substr($uri,0,$pos+1);
522: return $rdir.$filename;
523: }
524: 
525: 
526: ?>