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