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