File: 1.09.6a/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-2010 ";
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: 		$usid=$NATS->Cfg->Get("freenats.tracker.usid","");
169: 		if ($usid=="")
170: 			{ // generate usid if not already set
171: 			// usid form XYZ-XYZ-XYZ...
172: 			$allow="abcdef0123456789";
173: 			$allow_len=strlen($allow);
174: 			mt_srand(microtime()*1000000);
175: 			$first_set=1;
176: 			for ($a=0; $a<5; $a++) // blocks
177: 				{
178: 				if ($first_set==1) $first_set=0;
179: 				else $usid.="-";
180: 				for ($b=0; $b<10; $b++)
181: 					{
182: 					$c=mt_rand(0,$allow_len-1);
183: 					$usid.=$allow[$c];
184: 					}
185: 				}
186: 			$NATS->Cfg->Set("freenats.tracker.usid",$usid);
187: 			}
188: 			
189: 		// get some more data
190: 		$sn=explode("/",$_SERVER['SCRIPT_NAME']);
191: 		$script=$sn[count($sn)-1];
192: 		
193: 		// show tracking image
194: 		echo "<img src=\"http://www.purplepixie.org/freenats/report/ping.png.php?data=v=".$NATS->Version."+p=".$script."&type=ping&usid=".$usid."\" width=1 height=1>\n";
195: 		}
196: 	}
197: 
198: if ($NATS->Cfg->Get("site.popupmessage")=="1")
199: 	{
200: 	if (count($poplist)>0)
201: 		{
202: 		echo "\n<script type=\"text/javascript\">\n";
203: 		
204: 		foreach($poplist as $pop)
205: 			{
206: 			echo "alert('".$pop."');\n";
207: 			}
208: 			
209: 		echo "</script>\n";
210: 		}
211: 	}
212: echo "\n</body></html>\n";
213: }
214: 
215: function UL_Error($task="")
216: {
217: Screen_Header("Insufficient Access");
218: echo "<br>Sorry but your user has insufficient access to perform task (".$task.").<br><br>";
219: echo "<a href=main.php>Please click here to continue.</a><br><br>";
220: Screen_Footer();
221: exit();
222: }
223: 
224: function Session_Error()
225: {
226: global $REQUEST_URI;
227: header("Location: ./?login_msg=Invalid+or+Expired+Session&url=".urlencode($REQUEST_URI));
228: exit();
229: }
230: 
231: function nicedt($ts)
232: {
233: global $NATS;
234: $form="H:i:s d/m/Y";
235: if (isset($NATS)) $form=$NATS->Cfg->Get("site.dtformat","H:i:s d/m/Y");
236: if ($ts<=0) return "never";
237: return date($form,$ts);
238: }
239: 
240: function enicedt($ts)
241: {
242: echo nicedt($ts);
243: }
244: 
245: function nicediff($diff)
246: {
247: $hr=0;
248: $mn=0;
249: $se=0;
250: if ($diff>59)
251: 	{
252: 	$mn=round($diff/60,0);
253: 	$se=$diff%60;
254: 	if ($mn>59)
255: 		{
256: 		$hr=round($mn/60,0);
257: 		$mn=$mn%60;
258: 		}
259: 	}
260: else $se=$diff;
261: $s="";
262: if ($hr<10) $s="0";
263: $s.=$hr.":";
264: if ($mn<10) $s.="0";
265: $s.=$mn.":";
266: if ($se<10) $s.="0";
267: $s.=$se;
268: return $s;
269: }
270: 
271: function dtago($ts,$sayago=true)
272: {
273: if ($ts<=0) return "never";
274: $now=time();
275: $diff=$now-$ts;
276: $s=nicediff($diff);
277: if ($sayago) $s.=" ago";
278: return $s;
279: }
280: 
281: function nicenextx($nextx)
282: {
283: if ($nextx<=0) return "Now";
284: $diff=$nextx-time();
285: if ($diff<0)
286: 	{
287: 	$sign=" ago";
288: 	$diff=0-$diff;
289: 	}
290: else $sign="";
291: return nicediff($diff).$sign;
292: }
293: 
294: function edtago($ts)
295: {
296: echo dtago($ts);
297: }
298: 
299: function smartx($x) // smart handling of unixtime x variables
300: {
301: if ($x==0) return time();	// 0 = now
302: else if ($x<0)				// -z = now - z seconds
303: 	return (time()+$x);		// negative number so +
304: else						// positive number so is a unixtime
305: 	return $x;
306: }
307: 
308: $allowed="00123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@_-.,:&/~%=+(){}[]#?$";
309: 
310: function nices($s)
311: {
312: global $allowed;
313: $o="";
314: for ($a=0; $a<strlen($s); $a++)
315: 	{
316: 	$c=$s[$a];
317: 	if (strpos($allowed,$c)===false)
318: 		{
319: 		// skip it
320: 		}
321: 	else $o.=$c;
322: 	}
323: return $o;
324: }
325: /* // Old Static List Function
326: function ShowIcons()
327: {
328: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup;
329: $c=0;
330: echo "<table border=0>";
331: $cc=0;
332: for ($a=0; $a<count($fnIcons); $a++)
333: 	{
334: 	if ($cc==0) echo "<tr>";
335: 	echo "<td valign=top align=center><img src=icons/".$fnIcons[$a]."><br>".$fnIcons[$a]."<br>";
336: 	if ($a==$fnIcon_DefNode) echo "<i>Node Default</i> ";
337: 	if ($a==$fnIcon_DefGroup) echo "<i>Group Default</i>";
338: 	echo "</td>";
339: 	$cc++;
340: 	if ($cc>=5)
341: 		{
342: 		echo "</tr>";
343: 		$cc=0;
344: 		}
345: 	}
346: if ($cc>0) echo "</tr>";
347: echo "</table>";
348: }
349: */
350: 
351: function GetIcons()
352: {
353: $iconFiles=glob("icons/{*.gif,*.GIF,*.jpg,*.JPG,*.jpeg,*.JPEG,*.png,*.PNG}", GLOB_BRACE);
354: for($a=0;$a<count($iconFiles);$a++)
355: 	$iconFiles[$a]=substr($iconFiles[$a],6);
356: return $iconFiles;
357: }
358: 
359: 
360: function ShowIcons()
361: {
362: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup;
363: $c=0;
364: echo "<table border=0>";
365: $cc=0;
366: $iconFiles=GetIcons();
367: for ($a=0; $a<count($iconFiles); $a++)
368: 	{
369: 	$icon=$iconFiles[$a];
370: 	if ($cc==0) echo "<tr>";
371: 	echo "<td valign=top align=center><img src=icons/".$icon."><br>".$icon."<br>";
372: 	if ($icon==$fnIcons[$fnIcon_DefNode]) echo "<i>Node Default</i> ";
373: 	if ($a==$fnIcons[$fnIcon_DefGroup]) echo "<i>Group Default</i>";
374: 	echo "</td>";
375: 	$cc++;
376: 	if ($cc>=5)
377: 		{
378: 		echo "</tr>";
379: 		$cc=0;
380: 		}
381: 	}
382: if ($cc>0) echo "</tr>";
383: echo "</table>";
384: }
385: 
386: 
387: 
388: function NodeIcon($nodeid)
389: {
390: global $NATS,$fnIcons,$fnIcon_DefNode;
391: $q="SELECT nodeicon FROM fnnode WHERE nodeid=\"".ss($nodeid)."\"";
392: $r=$NATS->DB->Query($q);
393: if ($row=$NATS->DB->Fetch_Array($r)) 
394: 	{
395: 	if ($row['nodeicon']!="") return $row['nodeicon'];
396: 	}
397: return $fnIcons[$fnIcon_DefNode];
398: }
399: 
400: function GroupIcon($groupid)
401: {
402: global $NATS,$fnIcons,$fnIcon_DefGroup;
403: $q="SELECT groupicon FROM fngroup WHERE groupid=\"".ss($groupid)."\"";
404: $r=$NATS->DB->Query($q);
405: if ($row=$NATS->DB->Fetch_Array($r)) 
406: 	{
407: 	if ($row['groupicon']!="") return $row['groupicon'];
408: 	}
409: return $fnIcons[$fnIcon_DefGroup];
410: }
411: 
412: function np_tiny($nodeid,$text=true,$nodename="",$jslink=false)
413: {
414: global $NATS;
415: $al=$NATS->NodeAlertLevel($nodeid);
416: echo "<table class=\"nptiny-al".$al."\">";
417: echo "<tr><td valign=center align=center>";
418: if ($jslink) echo "<a href=\"javascript:nodeClick('".$nodeid."');\">";
419: else echo "<a href=node.php?nodeid=".$nodeid.">";
420: echo "<img src=\"icons/".NodeIcon($nodeid)."\" border=0>";
421: echo "</a>";
422: if ($text)
423: 	{
424: 	if ($nodename=="") $nodename=$nodeid;
425: 	
426: 	//$words=explode(" ",$nodename);
427: 	
428: 	// messy but there you go...
429: 	
430: 	$max_on_line=7;
431: 	$max_lines=2;
432: 	$len=strlen($nodename);
433: 	$out="";
434: 	$linecount=0;
435: 	$charcount=0;
436: 	for ($a=0; $a<$len; $a++)
437: 		{
438: 			
439: 		$char=$nodename[$a];
440: 		
441: 		if ($char==" ")
442: 			{
443: 			$linecount++;
444: 			$charcount=0;
445: 			}
446: 		else $charcount++;
447: 		
448: 		if ($charcount>=$max_on_line) 
449: 			{
450: 			$a=$len+10;
451: 			$out.="..";
452: 			}
453: 		else if ($linecount>=$max_lines) 
454: 			{
455: 			$a=$len+10;
456: 			$out.="..";
457: 			}
458: 		else $out.=$char;
459: 		
460: 		}
461: 	//if ($a==($len+10)) $out.="..";
462: 	$nodename=$out;
463: 	
464: 	$size=10;
465: 		
466: /* -- size-based	
467: 	$len=strlen($nodename);
468: 	if ($len<9) $size=10;
469: 	else if ($len<15) $size=8;
470: 	else if ($len<20) $size=7;
471: 	else
472: 		{
473: 		$size=6;
474: 		$nodename=substr($nodename,0,18)."..";
475: 		}
476: */
477: 	
478: 	echo "<br><b class=\"al".$al."\" style=\"font-size: ".$size."pt;\">".$nodename."</b>";
479: 	}
480: echo "</td></tr></table>";
481: }
482: 
483: function ng_tiny($groupid,$groupname="",$text=true)
484: {
485: global $NATS;
486: // to do - get groupname if not sent but F--- it for now
487: $al=$NATS->GroupAlertLevel($groupid);
488: echo "<table class=\"nptiny-al".$al."\">";
489: echo "<tr><td valign=center align=center>";
490: echo "<a href=group.php?groupid=".$groupid.">";
491: echo "<img src=\"icons/".GroupIcon($groupid)."\" border=0>";
492: echo "</a>";
493: if ($text)
494: 	{
495: 	echo "<br><b class=\"al".$al."\">".$groupname."</b>";
496: 	}
497: echo "</td></tr></table>";
498: }
499: 
500: function ng_big($groupid,$groupname="",$groupdesc="",$groupicon="")
501: {
502: global $NATS;
503: if ($groupicon=="") $groupicon=GroupIcon($groupid);
504: $al=$NATS->GroupAlertLevel($groupid);
505: echo "<table class=\"npbig-al".$al."\">";
506: echo "<tr><td align=left valign=top>";
507: echo "<table class=\"nicetable\" width=300>";
508: echo "<tr><td align=right>Group Name :";
509: echo "</td><td align=left><a href=group.php?groupid=".$groupid.">".$groupname."</a></td></tr>";
510: echo "<tr><td align=right>Description :";
511: echo "</td><td align=left>".$groupdesc."</td></tr>";
512: echo "<tr><td align=right>Status :</td><td align=left>";
513: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>";
514: echo "</table></td>";
515: //echo "<td align=left valign=top align=right width=60>";
516: //echo "<img src=icons/".GroupIcon($groupid).">";
517: //echo "</td>";
518: echo "</tr>";
519: echo "</table>";
520: }
521: 
522: function np_big($nodeid,$nodename="",$nodedesc="",$nodeicon="",$jslink=false)
523: {
524: global $NATS;
525: if ($nodedesc=="") $nodedesc="&nbsp;";
526: if ($nodeicon=="") $nodeicon=NodeIcon($nodeid);
527: $al=$NATS->NodeAlertLevel($nodeid);
528: echo "<table class=\"npbig-al".$al."\">";
529: echo "<tr><td align=left valign=top>";
530: echo "<table class=\"nicetable\" width=300>";
531: echo "<tr><td align=right>Node Name :";
532: if ($nodename=="") $nodename=$nodeid;
533: echo "</td><td align=left>";
534: if ($jslink) echo "<a href=\"javascript:nodeClick('".$nodeid."');\">";
535: else echo "<a href=node.php?nodeid=".$nodeid.">";
536: echo $nodename."</a></td></tr>";
537: echo "<tr><td align=right>Description :";
538: echo "</td><td align=left>".$nodedesc."</td></tr>";
539: echo "<tr><td align=right>Status :</td><td align=left>";
540: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>";
541: echo "</table></td>";
542: //echo "<td align=left valign=top align=right width=60>";
543: //echo "<img src=icons/".GroupIcon($groupid).">";
544: //echo "</td>";
545: echo "</tr>";
546: echo "</table>";
547: }
548: 
549: function GetAbsolute($filename="")
550: { // sooooooooo messy but looks like the ONLY FRICKIN' WAY!
551: if ((isset($_SERVER['HTTPS']))&&($_SERVER['HTTPS']!="")) $uri="https://";
552: else $uri="http://";
553: $uri.=$_SERVER['HTTP_HOST'];
554: $uri.=$_SERVER['REQUEST_URI'];
555: $pos=strripos($uri,"/");
556: $rdir=substr($uri,0,$pos+1);
557: return $rdir.$filename;
558: }
559: 
560: 
561: ?>
562: